Index: src/server/adminmanager.h =================================================================== --- src/server/adminmanager.h (Revision 1716) +++ src/server/adminmanager.h (Arbeitskopie) @@ -292,6 +292,9 @@ /** Transfers an item from one client to another */ void TransferItem(MsgEntry* me, psAdminCmdMessage& msg, AdminCmdData& data, Client* source, Client* target); + /** Checks the presence of items */ + void CheckItem(MsgEntry* me, psAdminCmdMessage& msg, AdminCmdData& data, Client* target); + /** Freezes a client, preventing it from doing anything. */ void FreezeClient(MsgEntry* me, psAdminCmdMessage& msg, AdminCmdData& data, Client* client, Client* target); Index: src/server/adminmanager.cpp =================================================================== --- src/server/adminmanager.cpp (Revision 1716) +++ src/server/adminmanager.cpp (Arbeitskopie) @@ -51,6 +51,7 @@ #include "bulkobjects/psitem.h" #include "bulkobjects/pssectorinfo.h" #include "bulkobjects/pstrait.h" +#include "bulkobjects/pscharinventory.h" #include "rpgrules/factions.h" @@ -438,6 +439,22 @@ } return true; } + /* TODO baustelle */ + else if (command == "/checkitem" ) + { + player = words[1]; + value = words.GetInt(2); + if (value) + { + item = words.GetTail(3); + } + else + { + value = 1; + item = words.GetTail(2); + } + return true; + } else if (command == "/thunder") { sector = words[1]; @@ -1226,6 +1243,11 @@ { TransferItem(me, msg, data, targetclient, client); } + /* TODO baustelle */ + else if (data.command == "/checkitem" ) + { + CheckItem(me, msg, data, targetclient); + } else if (data.command == "/freeze") { FreezeClient(me, msg, data, client, targetclient); @@ -5968,7 +5990,7 @@ if (data.value == 0 || data.item.IsEmpty()) { - psserver->SendSystemError(me->clientnum, "Syntax: \"/[giveitem|takeitem] [target] [quantity|'all'|''] [item]\""); + psserver->SendSystemError(me->clientnum, "Syntax: \"/[giveitem|takeitem] [target] [quantity|'all'|''] [item|tria]\""); return; } @@ -5982,71 +6004,169 @@ psCharacter* targetchar = target->GetCharacterData(); psCharacter* sourcechar = source->GetCharacterData(); - InventoryTransaction srcTran( &sourcechar->Inventory() ); + - //int slot = sourcechar->Inventory().FindItemInTopLevelBulkWithStats(itemstats); - size_t slot = sourcechar->Inventory().FindItemStatIndex(itemstats); - if (slot == SIZET_NOT_FOUND) + //int itemIndex = sourcechar->Inventory().FindItemInTopLevelBulkWithStats(itemstats); + size_t itemIndex = sourcechar->Inventory().FindItemStatIndex(itemstats); + + if (itemIndex != SIZET_NOT_FOUND) { + InventoryTransaction srcTran( &sourcechar->Inventory() ); + psItem* item; + item = sourcechar->Inventory().RemoveItemIndex(itemIndex,data.value); // data.value is the stack count to move, or -1 + if (!item) + { + Error2("Cannot RemoveItemIndex on itemIndex %zu.\n", itemIndex); + psserver->SendSystemError(me->clientnum, "Cannot remove %s from %s's inventory.", + data.item.GetData(), source->GetActor()->GetName() ); + return; + } + psserver->GetCharManager()->UpdateItemViews(source->GetClientNum()); + + if (item->GetStackCount() < data.value) + { + psserver->SendSystemError(me->clientnum, "There are only %d, not %d in the stack.", item->GetStackCount(), data.value ); + return; + } + + bool wasEquipped = item->IsEquipped(); + + // Now here we handle the target machine + InventoryTransaction trgtTran( &targetchar->Inventory() ); + + if (!targetchar->Inventory().Add(item)) + { + psserver->SendSystemError(me->clientnum, "Target inventory is too full to accept item transfer."); + return; + } + psserver->GetCharManager()->UpdateItemViews(target->GetClientNum()); + + // Inform the GM doing the transfer + psserver->SendSystemOK(me->clientnum, "%s transferred from %s's %s to %s", + item->GetName(), + source->GetActor()->GetName(), + wasEquipped?"equipment":"inventory", + target->GetActor()->GetName() ); + + // If we're giving to someone else, notify them + if (target->GetClientNum() != me->clientnum) + { + psserver->SendSystemOK(target->GetClientNum(), "You were given %s by GM %s.", + item->GetName(), + source->GetActor()->GetName() ); + } + + // If we're taking from someone else, notify them + if (source->GetClientNum() != me->clientnum) + { + psserver->SendSystemResult(source->GetClientNum(), "%s was taken by GM %s.", + item->GetName(), + target->GetActor()->GetName() ); + } + + trgtTran.Commit(); + srcTran.Commit(); + return; + } + else if (data.item == "tria") + { + psMoney srcMoney = sourcechar->Money(); + psMoney targetMoney = targetchar->Money(); + int value = data.value; + if (value == -1) + { + value = srcMoney.GetTotal(); + } + else if (value > srcMoney.GetTotal()) + { + value = srcMoney.GetTotal(); + psserver->SendSystemError(me->clientnum, "Only %d tria taken.",srcMoney.GetTotal()); + } + psMoney transferMoney(0, 0, 0, value); + transferMoney = transferMoney.Normalized(); + sourcechar->SetMoney( srcMoney - transferMoney ); + targetchar->SetMoney( targetMoney + transferMoney ); + // If we're taking from someone else, notify them + if (source->GetClientNum() != me->clientnum) + { + psserver->SendSystemResult(source->GetClientNum(), "%d tria was taken by %s.", + value, + target->GetActor()->GetName() ); + } + return; + } + else + { psserver->SendSystemError(me->clientnum, "Cannot find any %s in %s's inventory.", data.item.GetData(), source->GetActor()->GetName() ); - return; + return; } +} - psItem* item; - item = sourcechar->Inventory().RemoveItemIndex(slot,data.value); // data.value is the stack count to move, or -1 - if (!item) +void AdminManager::CheckItem(MsgEntry* me, psAdminCmdMessage& msg, AdminCmdData& data, Client* target) +{ + if (!target || !target->GetCharacterData()) { - Error2("Cannot RemoveItemIndex on slot %zu.\n", slot); - psserver->SendSystemError(me->clientnum, "Cannot remove %s from %s's inventory.", - data.item.GetData(), source->GetActor()->GetName() ); + psserver->SendSystemError(me->clientnum, "Invalid character to check"); return; } - psserver->GetCharManager()->UpdateItemViews(source->GetClientNum()); - - if (item->GetStackCount() < data.value) + + if (data.value == 0 || data.item.IsEmpty()) { - psserver->SendSystemError(me->clientnum, "There are only %d, not %d in the stack.", item->GetStackCount(), data.value ); + psserver->SendSystemError(me->clientnum, "Syntax: \"/[checkitem] [target] [quantity|''] [item|tria]\""); return; } - bool wasEquipped = item->IsEquipped(); - - // Now here we handle the target machine - InventoryTransaction trgtTran( &targetchar->Inventory() ); - - if (!targetchar->Inventory().Add(item)) + psItemStats* itemstats = CacheManager::GetSingleton().GetBasicItemStatsByName(data.item); + if (!itemstats) { - psserver->SendSystemError(me->clientnum, "Target inventory is too full to accept item transfer."); + psserver->SendSystemError(me->clientnum, "Invalid item name"); return; } - psserver->GetCharManager()->UpdateItemViews(target->GetClientNum()); - // Inform the GM doing the transfer - psserver->SendSystemOK(me->clientnum, "%s transferred from %s's %s to %s", - item->GetName(), - source->GetActor()->GetName(), - wasEquipped?"equipment":"inventory", - target->GetActor()->GetName() ); + psCharacter* targetchar = target->GetCharacterData(); + size_t itemIndex = targetchar->Inventory().FindItemStatIndex(itemstats); + + if (itemIndex != SIZET_NOT_FOUND) + { + psItem* item; + item = targetchar->Inventory().GetInventoryIndexItem(itemIndex); + if (!item) + { + Error2("Cannot GetInventoryIndexItem on itemIndex %zu.\n", itemIndex); + psserver->SendSystemError(me->clientnum, "Cannot check %s from %s's inventory.", + data.item.GetData(), target->GetActor()->GetName() ); + return; + } - // If we're giving to someone else, notify them - if (target->GetClientNum() != me->clientnum) + if (item->GetStackCount() < data.value) + { + psserver->SendSystemOK(me->clientnum, "Cannot find %d %s.", data.value, data.item.GetData()); + } + else + { + psserver->SendSystemOK(me->clientnum, "Found %d %s.", data.value, data.item.GetData()); + } + return; + } + else if (data.item == "tria") { - psserver->SendSystemOK(target->GetClientNum(), "You were given %s by GM %s.", - item->GetName(), - source->GetActor()->GetName() ); + psMoney targetMoney = targetchar->Money(); + if (data.value > targetMoney.GetTotal()) + { + psserver->SendSystemOK(me->clientnum, "Cannot find %d tria.", data.value); + } + else + { + psserver->SendSystemOK(me->clientnum, "Found %d tria.", data.value); + } + return; } - - // If we're taking from someone else, notify them - if (source->GetClientNum() != me->clientnum) + else { - psserver->SendSystemResult(source->GetClientNum(), "%s was taken by GM %s.", - item->GetName(), - target->GetActor()->GetName() ); + psserver->SendSystemOK(me->clientnum, "Cannot find %s.", data.item.GetData()); + return; } - - trgtTran.Commit(); - srcTran.Commit(); } void AdminManager::FreezeClient(MsgEntry* me, psAdminCmdMessage& msg, AdminCmdData& data, Client* client, Client* target) Index: src/server/database/mysql/command_access.sql =================================================================== --- src/server/database/mysql/command_access.sql (Revision 1716) +++ src/server/database/mysql/command_access.sql (Arbeitskopie) @@ -273,6 +273,12 @@ INSERT INTO command_group_assignment VALUES( "quest list others", 24 ); INSERT INTO command_group_assignment VALUES( "quest list others", 23 ); INSERT INTO command_group_assignment VALUES( "quest list others", 22 ); +INSERT INTO command_group_assignment VALUES( "/checkitem", 30 ); +INSERT INTO command_group_assignment VALUES( "/checkitem", 26 ); +INSERT INTO command_group_assignment VALUES( "/checkitem", 25 ); +INSERT INTO command_group_assignment VALUES( "/checkitem", 24 ); +INSERT INTO command_group_assignment VALUES( "/checkitem", 23 ); +INSERT INTO command_group_assignment VALUES( "/checkitem", 22 ); # GM1 and above Index: data/help.xml =================================================================== --- data/help.xml (Revision 1716) +++ data/help.xml (Arbeitskopie) @@ -408,6 +408,9 @@ /charlist player Informs the GM of the IDs and names of all characters on the same account as the account of the given character. + /checkitem [target] [quantity|''] [item|tria] + +Commands used to check the presence of an item in another character. Example: "/checkitem Bob 42 tria" /crystal [interval] [max random interval modifier] [amount] [range] [item] Create a new hunt location which spawns an item in interval + random secs up to a max of amount within the range. @@ -457,7 +460,7 @@ value (in milliseconds). With specified sector, it starts fog with default values: density 200, fade 10 sec, soft white (r 200, g 200, w 200). Use /fog sector off or /fog sector -1 for resetting. - /giveitem [target] [quantity|'all'|''] [item] + /giveitem [target] [quantity|'all'|''] [item|tria] Commands used to transfer an item from you to another character. Example: "/giveitem Bob Apple" /impersonate name command message @@ -637,7 +640,7 @@ With specified sector, it starts snow with default values: density 4000 flakes, length 10 minutes and 10 seconds of fade. The maximum number of flakes allowed is 8000. Use /snow sector 0 or /snow sector off for ending the event. - /takeitem [target] [quantity|'all'|''] [item] + /takeitem [target] [quantity|'all'|''] [item|tria] Command used to transfer an item to you from another character. Example: "/takeitem target 3 Sabre" /teleport <subject> <destination>