public void OnMoveItem(SagaMap.Packets.Client.MoveItem p) { if (this.state != SESSION_STATE.MAP_LOADED) { return; } Packets.Client.ITEM_MOVE_TYPE moveType = p.GetMoveType(); if (moveType == Packets.Client.ITEM_MOVE_TYPE.EquToInv) { // unequip, equip items are not stackable? byte index, amount; UnequipItemResult ures = this.Char.inv.UnequipItem(p.GetSourceIndex(), out index, out amount); if (ures == UnequipItemResult.NEW_INDEX || ures == UnequipItemResult.STACKED) { Packets.Server.MoveItem p1 = new SagaMap.Packets.Server.MoveItem(); p1.SetMoveType(SagaMap.Packets.Server.ITEM_MOVE_TYPE.EquToInv); p1.SetSourceIndex(p.GetSourceIndex()); p1.SetDestIndex(index); this.netIO.SendPacket(p1, this.SessionID); Item item = this.Char.inv.GetItem(CONTAINER_TYPE.INVENTORY, index); item.equipSlot = -1; MapServer.charDB.UpdateItem(this.Char, item); Bonus.BonusHandler.Instance.EquiqItem(this.Char, item, true); SkillHandler.CalcHPSP(ref this.Char); SendCharStatus(0); SendExtStats(); SendBattleStatus(); this.map.SendEventToAllActorsWhoCanSeeActor(Map.EVENT_TYPE.CHANGE_EQUIP, new Map.ChangeEquipArgs((EQUIP_SLOT)(p.GetSourceIndex()), 0), this.Char, false); } else { SendMessage("Saga", "unequip error"); } } else if (moveType == Packets.Client.ITEM_MOVE_TYPE.InvToEqu) { // equip Item item; Item itemori = null; if (this.Char.inv.EquipList.ContainsKey((EQUIP_SLOT)p.GetDestIndex())) { itemori = this.Char.inv.EquipList[(EQUIP_SLOT)p.GetDestIndex()]; } EquipItemResult eres = this.Char.inv.EquipItem(p.GetSourceIndex(), p.GetDestIndex(), out item); if (eres == EquipItemResult.NO_ERROR) { Packets.Server.MoveItem p1 = new SagaMap.Packets.Server.MoveItem(); p1.SetMoveType(SagaMap.Packets.Server.ITEM_MOVE_TYPE.InvToEqu); p1.SetSourceIndex(p.GetSourceIndex()); p1.SetDestIndex(item.index); item.equipSlot = item.index; MapServer.charDB.UpdateItem(this.Char, item); this.netIO.SendPacket(p1, this.SessionID); if (itemori != null) { Bonus.BonusHandler.Instance.EquiqItem(this.Char, itemori, true); itemori.equipSlot = -1; MapServer.charDB.UpdateItem(this.Char, itemori); } Bonus.BonusHandler.Instance.EquiqItem(this.Char, item, false); SkillHandler.CalcHPSP(ref this.Char); SendCharStatus(0); SendExtStats(); SendBattleStatus(); this.map.SendEventToAllActorsWhoCanSeeActor(Map.EVENT_TYPE.CHANGE_EQUIP, new Map.ChangeEquipArgs((EQUIP_SLOT)(item.index), item.id), this.Char, false); } else if (eres == EquipItemResult.NOT_EQUIPABLE) { SendMessage("Saga", "error, item is not equipable"); } else if (eres == EquipItemResult.WRONG_EQUIPSLOT) { SendMessage("Saga", "error, wrong equip slot"); } else { SendMessage("Saga", "error, cannot equip item"); } } else if (moveType == Packets.Client.ITEM_MOVE_TYPE.InvToSto) { Item item; byte index, amount; item = this.Char.inv.GetItem(CONTAINER_TYPE.INVENTORY, p.GetSourceIndex()); if (item == null) { return; } if (!this.Char.inv.HasFreeSpaceStorage()) { return; } if (this.Char.inv.AddItemStorage(item, out index, out amount) == AddItemResult.ERROR) { return; } this.Char.inv.DeleteItem(CONTAINER_TYPE.INVENTORY, p.GetSourceIndex(), item.id, p.GetAmount(), out amount); MapServer.charDB.DeleteItem(this.Char, item); MapServer.charDB.NewStorage(this.Char, item); Packets.Server.MoveItem p1 = new SagaMap.Packets.Server.MoveItem(); p1.SetMoveType(SagaMap.Packets.Server.ITEM_MOVE_TYPE.InvToSto); p1.SetSourceIndex(p.GetSourceIndex()); p1.SetDestIndex(item.index); this.netIO.SendPacket(p1, this.SessionID); } else if (moveType == Packets.Client.ITEM_MOVE_TYPE.StoToInv) { Item item; byte amount; item = this.Char.inv.GetItem(CONTAINER_TYPE.STORAGE, p.GetSourceIndex()); if (item == null) { return; } if (!this.Char.inv.HasFreeSpace()) { return; } if (this.Char.inv.AddItem(item) == AddItemResult.ERROR) { return; } this.Char.inv.DeleteItem(CONTAINER_TYPE.STORAGE, p.GetSourceIndex(), item.id, p.GetAmount(), out amount); MapServer.charDB.DeleteStorage(this.Char, item); MapServer.charDB.NewItem(this.Char, item); Packets.Server.MoveItem p1 = new SagaMap.Packets.Server.MoveItem(); p1.SetMoveType(SagaMap.Packets.Server.ITEM_MOVE_TYPE.StoToInv); p1.SetSourceIndex(p.GetSourceIndex()); p1.SetDestIndex(item.index); this.netIO.SendPacket(p1, this.SessionID);; } //Send Answer // Do item movement stuff in inventory db? Packets.Server.MoveReply sendPacket = new SagaMap.Packets.Server.MoveReply(); // Todo : Switch result of move and obtain relevent string to send from GameStringTable sendPacket.SetMessage(0); this.netIO.SendPacket(sendPacket, this.SessionID); }
public void OnMoveItem(SagaMap.Packets.Client.MoveItem p) { if (this.state != SESSION_STATE.MAP_LOADED) return; Packets.Client.ITEM_MOVE_TYPE moveType = p.GetMoveType(); if (moveType == Packets.Client.ITEM_MOVE_TYPE.EquToInv) { // unequip, equip items are not stackable? byte index, amount; UnequipItemResult ures = this.Char.inv.UnequipItem(p.GetSourceIndex(), out index, out amount); if (ures == UnequipItemResult.NEW_INDEX || ures == UnequipItemResult.STACKED) { Packets.Server.MoveItem p1 = new SagaMap.Packets.Server.MoveItem(); p1.SetMoveType(SagaMap.Packets.Server.ITEM_MOVE_TYPE.EquToInv); p1.SetSourceIndex(p.GetSourceIndex()); p1.SetDestIndex(index); this.netIO.SendPacket(p1, this.SessionID); Item item = this.Char.inv.GetItem(CONTAINER_TYPE.INVENTORY, index); item.equipSlot = -1; MapServer.charDB.UpdateItem(this.Char, item); Bonus.BonusHandler.Instance.EquiqItem(this.Char, item, true); SkillHandler.CalcHPSP(ref this.Char); SendCharStatus(0); SendExtStats(); SendBattleStatus(); this.map.SendEventToAllActorsWhoCanSeeActor(Map.EVENT_TYPE.CHANGE_EQUIP, new Map.ChangeEquipArgs((EQUIP_SLOT)(p.GetSourceIndex()), 0), this.Char, false); } else SendMessage("Saga", "unequip error"); } else if (moveType == Packets.Client.ITEM_MOVE_TYPE.InvToEqu) { // equip Item item; Item itemori = null; if (this.Char.inv.EquipList.ContainsKey((EQUIP_SLOT)p.GetDestIndex())) { itemori = this.Char.inv.EquipList[(EQUIP_SLOT)p.GetDestIndex()]; } EquipItemResult eres = this.Char.inv.EquipItem(p.GetSourceIndex(), p.GetDestIndex(), out item); if (eres == EquipItemResult.NO_ERROR) { Packets.Server.MoveItem p1 = new SagaMap.Packets.Server.MoveItem(); p1.SetMoveType(SagaMap.Packets.Server.ITEM_MOVE_TYPE.InvToEqu); p1.SetSourceIndex(p.GetSourceIndex()); p1.SetDestIndex(item.index); item.equipSlot = item.index; MapServer.charDB.UpdateItem(this.Char, item); this.netIO.SendPacket(p1, this.SessionID); if (itemori != null) { Bonus.BonusHandler.Instance.EquiqItem(this.Char, itemori, true); itemori.equipSlot = -1; MapServer.charDB.UpdateItem(this.Char, itemori); } Bonus.BonusHandler.Instance.EquiqItem(this.Char, item, false); SkillHandler.CalcHPSP(ref this.Char); SendCharStatus(0); SendExtStats(); SendBattleStatus(); this.map.SendEventToAllActorsWhoCanSeeActor(Map.EVENT_TYPE.CHANGE_EQUIP, new Map.ChangeEquipArgs((EQUIP_SLOT)(item.index), item.id), this.Char, false); } else if (eres == EquipItemResult.NOT_EQUIPABLE) SendMessage("Saga", "error, item is not equipable"); else if (eres == EquipItemResult.WRONG_EQUIPSLOT) SendMessage("Saga", "error, wrong equip slot"); else SendMessage("Saga", "error, cannot equip item"); } else if (moveType == Packets.Client.ITEM_MOVE_TYPE.InvToSto) { Item item; byte index, amount; item = this.Char.inv.GetItem(CONTAINER_TYPE.INVENTORY, p.GetSourceIndex()); if (item == null) return; if (!this.Char.inv.HasFreeSpaceStorage()) return; if (this.Char.inv.AddItemStorage(item, out index, out amount) == AddItemResult.ERROR) return; this.Char.inv.DeleteItem(CONTAINER_TYPE.INVENTORY, p.GetSourceIndex(), item.id, p.GetAmount(), out amount); MapServer.charDB.DeleteItem(this.Char, item); MapServer.charDB.NewStorage(this.Char, item); Packets.Server.MoveItem p1 = new SagaMap.Packets.Server.MoveItem(); p1.SetMoveType(SagaMap.Packets.Server.ITEM_MOVE_TYPE.InvToSto); p1.SetSourceIndex(p.GetSourceIndex()); p1.SetDestIndex(item.index); this.netIO.SendPacket(p1, this.SessionID); } else if (moveType == Packets.Client.ITEM_MOVE_TYPE.StoToInv) { Item item; byte amount; item = this.Char.inv.GetItem(CONTAINER_TYPE.STORAGE, p.GetSourceIndex()); if (item == null) return; if (!this.Char.inv.HasFreeSpace()) return; if (this.Char.inv.AddItem(item) == AddItemResult.ERROR) return; this.Char.inv.DeleteItem(CONTAINER_TYPE.STORAGE, p.GetSourceIndex(), item.id, p.GetAmount(), out amount); MapServer.charDB.DeleteStorage(this.Char, item); MapServer.charDB.NewItem(this.Char, item); Packets.Server.MoveItem p1 = new SagaMap.Packets.Server.MoveItem(); p1.SetMoveType(SagaMap.Packets.Server.ITEM_MOVE_TYPE.StoToInv); p1.SetSourceIndex(p.GetSourceIndex()); p1.SetDestIndex(item.index); this.netIO.SendPacket(p1, this.SessionID); ; } //Send Answer // Do item movement stuff in inventory db? Packets.Server.MoveReply sendPacket = new SagaMap.Packets.Server.MoveReply(); // Todo : Switch result of move and obtain relevent string to send from GameStringTable sendPacket.SetMessage(0); this.netIO.SendPacket(sendPacket, this.SessionID); }