Index: client_process.cpp =================================================================== --- client_process.cpp (revision 31) +++ client_process.cpp (working copy) @@ -1101,6 +1101,10 @@ this->AFK = (sa->parameter == 1); entity_list.QueueClients(this, app, true); } + //Father Nitwit: + else if (sa->type == AT_Split) { + this->auto_split = (sa->parameter == 1); + } else if (sa->type == AT_Sneak) { this->sneaking = (sa->parameter == 1); entity_list.QueueClients(this, app, true); @@ -4437,7 +4442,28 @@ // update our state anyway, and make sure they had enough to begin // with. Split_Struct *split = (Split_Struct *)app->pBuffer; - Message(13, "Sorry, split is not implemented yet."); + //Implemented by Father Nitwit + //Per the note above, Im not exactly sure what to do on error + //to notify the client of the error... +Message(13, "Starting to split: %dcp, %dsp, %dgp, %d pp", split->copper, split->silver, split->gold, split->platinum); + if(!isgrouped) { + Message(13, "You can not split money if your not in a group."); + break; + } + Group *cgroup = entity_list.GetGroupByClient(this); + if(cgroup == NULL) { + //invalid group, not sure if we should say more... + Message(13, "You can not split money if your not in a group."); + break; + } + + uint32 sum = split->copper + 10 * split->silver + 100 * split->gold + 1000 * split->platinum; + if(!TakeMoneyFromPP(sum)) { + Message(13, "You do not have enough money to do that split."); + break; + } + cgroup->SplitMoney(split->copper, split->silver, split->gold, split->platinum); + break; } case OP_CrashDump: Index: client.cpp =================================================================== --- client.cpp (revision 37) +++ client.cpp (working copy) @@ -197,6 +197,8 @@ camp_timer->Disable(); pLastUpdate = 0; pLastUpdateWZ = 0; + //father nitwit: + auto_split = false; // Kaiyodo - initialise haste variable m_tradeskill_object = NULL; IsSettingGuildDoor = false; Index: groups.h =================================================================== --- groups.h (revision 31) +++ groups.h (working copy) @@ -59,6 +59,9 @@ int32 GetHighestLevel(); void QueuePacket(const APPLAYER *app, bool ack_req = true); void TeleportGroup(Mob* sender, int32 zoneID, float x, float y, float z); + + //father nitwit: + void SplitMoney(uint32 copper, uint32 gold, uint32 silver, uint32 platinum); bool disbandcheck; bool castspell; Index: PlayerCorpse.cpp =================================================================== --- PlayerCorpse.cpp (revision 31) +++ PlayerCorpse.cpp (working copy) @@ -715,12 +715,21 @@ if (this->GetPlatinum()>10000) this->RemoveCash(); #endif - d->copper = this->GetCopper(); - d->silver = this->GetSilver(); - d->gold = this->GetGold(); - d->platinum = this->GetPlatinum(); - client->AddMoneyToPP(this->GetCopper(),this->GetSilver(),this->GetGold(),this->GetPlatinum(),false); + if(client->isgrouped && client->AutoSplitEnabled() && entity_list.GetGroupByClient(client)) { + d->copper = 0; + d->silver = 0; + d->gold = 0; + d->platinum = 0; + Group *cgroup = entity_list.GetGroupByClient(client); + cgroup->SplitMoney(this->GetCopper(),this->GetSilver(),this->GetGold(),this->GetPlatinum()); + } else { + d->copper = this->GetCopper(); + d->silver = this->GetSilver(); + d->gold = this->GetGold(); + d->platinum = this->GetPlatinum(); + client->AddMoneyToPP(this->GetCopper(),this->GetSilver(),this->GetGold(),this->GetPlatinum(),false); + } this->RemoveCash(); } outapp->priority = 6; Index: groups.cpp =================================================================== --- groups.cpp (revision 31) +++ groups.cpp (working copy) @@ -384,6 +384,110 @@ } } } +} + +void Group::SplitMoney(uint32 copper, uint32 silver, uint32 gold, uint32 platinum) { + //avoid unneeded work + if(copper == 0 && silver == 0 && gold == 0 && platinum == 0) + return; + int i; + int8 membercount = 0; + for (i = 0; i < MAX_GROUP_MEMBERS; i++) { + if (members[i] != NULL) { + + membercount++; + } + } + + if (membercount == 0) + return; + + uint32 mod; + //try to handle round off error a little better + if(membercount > 1) { + mod = platinum % membercount; + if((mod) > 0) { + platinum -= mod; + gold += 10 * mod; + } + mod = gold % membercount; + if((mod) > 0) { + gold -= mod; + silver += 10 * mod; + } + mod = silver % membercount; + if((mod) > 0) { + silver -= mod; + copper += 10 * mod; + } + } + + //calculate the splits + //We can still round off copper pieces, but I dont care + uint32 cpsplit = copper / membercount; + uint32 spsplit = silver / membercount; + uint32 gpsplit = gold / membercount; + uint32 ppsplit = platinum / membercount; + + //make sure they at least get something, since they started with something... + if(cpsplit == 0 && spsplit == 0 && gpsplit == 0 && ppsplit == 0) + cpsplit = 1; + + for (i = 0; i < MAX_GROUP_MEMBERS; i++) { + if (members[i] != NULL && members[i]->IsClient()) { // If Group Member is Client + Client *c = members[i]->CastToClient(); + + c->AddMoneyToPP(cpsplit, spsplit, gpsplit, ppsplit, false); + + + //An OP_MoneyOnCorpse didnt seem to work... + + APPLAYER* outapp = new APPLAYER(OP_MoneyUpdate,sizeof(MoneyUpdate_Struct)); + MoneyUpdate_Struct* mus= (MoneyUpdate_Struct*)outapp->pBuffer; + mus->platinum = c->GetPP().platinum; + mus->gold = c->GetPP().gold; + mus->silver = c->GetPP().silver; + mus->copper = c->GetPP().copper; + + + c->QueuePacket(outapp); + + //This is prolly not the best way to do this... + char buf[64]; + buf[63] = '\0'; + string msg = "You receive"; + bool one = false; + + if(ppsplit > 0) { + snprintf(buf, 63, " %u platinum", ppsplit); + msg += buf; + one = true; + } + if(gpsplit > 0) { + if(one) + msg += ","; + snprintf(buf, 63, " %u gold", gpsplit); + msg += buf; + one = true; + } + if(spsplit > 0) { + if(one) + msg += ","; + snprintf(buf, 63, " %u silver", spsplit); + msg += buf; + one = true; + } + if(cpsplit > 0) { + if(one) + msg += ","; + snprintf(buf, 63, " %u copper", cpsplit); + msg += buf; + one = true; + } + msg += " as your split"; + c->Message(15, msg.c_str()); + } + } } bool Group::Process() Index: client.h =================================================================== --- client.h (revision 37) +++ client.h (working copy) @@ -345,6 +345,8 @@ //sint32 GetEquipmentMaterial(int8 material_slot); sint32 GetEquipmentColor(int8 material_slot); + //FatherNitwit: + inline bool AutoSplitEnabled() { return(auto_split); } bool GetReduceManaCostItem(int16 &spell_id, char *itemname); bool GetExtendedRangeItem(int16 &spell_id, char *itemname); @@ -456,6 +458,8 @@ bool revoked; int32 pQueuedSaveWorkID; int16 pClientSideTarget; + //father nitwit: + bool auto_split; PlayerProfile_Struct m_pp; Inventory m_inv;