public void AddItem(Player arrivedFrom, int slot, int count) { lock (TradeLock) { if (IsTradeFinished()) return; // should be impossible, but it's better to check if (arrivedFrom != Player1 && arrivedFrom != Player2) return; Storage storage = arrivedFrom.Equals(Player1) ? Storage1 : Storage2; if (storage.Locked) { SystemMessages.TradeListLocked.Send(arrivedFrom); return; } StorageItem item = Communication.Global.StorageService.GetItemBySlot(arrivedFrom.Inventory, slot + 20); if (item == null) return; if (!Communication.Global.StorageService.AddItem(arrivedFrom, storage, item.ItemId, count)) return; CheckLock(storage.Equals(Storage1) ? Storage2 : Storage1); Communication.Global.StorageService.RemoveItem(arrivedFrom, arrivedFrom.Inventory, slot, count); SystemMessages.YouAddedItemNameXItemAmountToTrade(item.ItemId, count).Send(arrivedFrom); SystemMessages.OpponentAddedItemNameItemAmount(arrivedFrom.PlayerData.Name, item.ItemId, count).Send( arrivedFrom.Equals(Player1) ? Player2 : Player1); UpdateWindow(); } }
public void ChangeMoney(Player player, long money) { if (!(player.Controller is PlayerTradeController)) return; PlayerTradeController controller = (PlayerTradeController) player.Controller; Storage storage = player.Equals(controller.Player1) ? controller.Storage1 : controller.Storage2; if(money < storage.Money) controller.RemoveMoney(player, storage.Money - money); else if(money > storage.Money) controller.AddMoney(player, money - storage.Money); }
public void AddMoney(Player arrivedFrom, long money) { lock (TradeLock) { if (IsTradeFinished()) return; if (arrivedFrom != Player1 && arrivedFrom != Player2) return; Storage storage = arrivedFrom.Equals(Player1) ? Storage1 : Storage2; if (storage.Locked) { SystemMessages.TradeListLocked.Send(arrivedFrom); return; } if (!Communication.Global.StorageService.RemoveMoney(arrivedFrom, arrivedFrom.Inventory, money)) return; Communication.Global.StorageService.AddMoneys(arrivedFrom, storage, money); CheckLock(arrivedFrom.Equals(Player1) ? Storage2 : Storage1); SystemMessages.YouOfferedMoney(storage.Money).Send(arrivedFrom); SystemMessages.OpponentOfferedMoney(arrivedFrom.PlayerData.Name, storage.Money).Send( arrivedFrom.Equals(Player1) ? Player2 : Player1); UpdateWindow(); } }
public void Lock(Player arrivedFrom) { lock (TradeLock) { if (IsTradeFinished()) return; if (arrivedFrom != Player1 && arrivedFrom != Player2) return; if (arrivedFrom.Equals(Player1)) { Storage1.Locked = !Storage1.Locked; if (Storage1.Locked) SystemMessages.OpponentLockedTradeList(Player1.PlayerData.Name).Send(Player1, Player2); } else { Storage2.Locked = !Storage2.Locked; if (Storage2.Locked) SystemMessages.OpponentLockedTradeList(Player2.PlayerData.Name).Send(Player1, Player2); } if (Storage1.Locked && Storage2.Locked) Accept(); else UpdateWindow(); } }