private void LoadItems() { EquippedItems = new Dictionary<ItemSlot, Equip>(); foreach (var eqp in character.Equips.Where(e => e.Slot < 0)) { Equip equip = new Equip(eqp); if (EquippedItems.ContainsKey(equip.SlotType)) { Log.WriteLine(LogLevel.Warn, "{0} has duplicate equipped in slot {1}.", Name, equip.SlotType); continue; } EquippedItems.Add(equip.SlotType, equip); } InventoryItems = new Dictionary<sbyte, Item>(); foreach (var eqp in character.Equips.Where(e => e.Slot >= 0)) { Equip equip = new Equip(eqp); if (InventoryItems.ContainsKey(equip.Slot)) { Log.WriteLine(LogLevel.Warn, "{0} has a duplicate item in slot {0}.", Name, equip.Slot); continue; } InventoryItems.Add(equip.Slot, equip); } foreach (var ditem in character.Items) { Item item = new Item(ditem); InventoryItems.Add((sbyte)item.Slot, item); } SkillsActive = new Dictionary<ushort, Skill>(); SkillsPassive = new Dictionary<ushort, Skill>(); foreach (var skill in character.Skills) { Skill s = new Skill(skill); if (s.IsPassive) { SkillsPassive.Add(s.ID, s); } else { SkillsActive.Add(s.ID, s); } } }
private void LoadSkillsFromDataTable(DataTable skilllistdata) { foreach (DataRow row in skilllistdata.Rows) { DatabaseSkill skill = new DatabaseSkill(); skill.ID = long.Parse(row["ID"].ToString()); skill.Upgrades = short.Parse(row["Upgrades"].ToString()); skill.Character = Character; skill.SkillID = short.Parse(row["SkillID"].ToString()); skill.IsPassive = (bool)row["IsPassive"]; Skill s = new Skill(skill); if (s.IsPassive) { SkillsPassive.Add(s.ID, s); } else { SkillsActive.Add(s.ID, s); } } }
public void UseItem(sbyte slot) { Item item; if (!InventoryItems.TryGetValue(slot, out item)) //TODO: not sure about return scrolls { //TODO: send item not found / error occured packet return; } if (item.Info.Level > Level) { Handler12.SendItemUsed(this, item, 1800); return; } if (((uint)item.Info.Jobs & (uint)Job) == 0) { Handler12.SendItemUsed(this, item, 1801); return; } if (item.Info.Type == ItemType.Useable) //potion { if (item.Info.Class == ItemClass.ReturnScroll) //return scroll { RecallCoordinate coord; MapInfo map; if (DataProvider.Instance.RecallCoordinates.TryGetValue(item.Info.InxName, out coord) && (map = DataProvider.Instance.MapsByID.Values.First(m => m.ShortName == coord.MapName)) != null) { Handler12.SendItemUsed(this, item); //No idea what this does, but normally it's sent. UseOneItemStack(item); ChangeMap(map.ID, coord.LinkX, coord.LinkY); //TODO: do this properly via world later. } else { Handler12.SendItemUsed(this, item, 1811); } } else if (item.Info.Class == ItemClass.Skillbook) { //TODO: passive skills! ActiveSkillInfo info; if (DataProvider.Instance.ActiveSkillsByName.TryGetValue(item.Info.InxName, out info)) { if (SkillsActive.ContainsKey(info.ID)) { Handler12.SendItemUsed(this, item, 1811); //character has this skill already } else { Handler12.SendItemUsed(this, item); UseOneItemStack(item); DatabaseSkill dskill = new DatabaseSkill(); dskill.Character = character; dskill.SkillID = (short)info.ID; dskill.IsPassive = false; dskill.Upgrades = 0; Program.Entity.AddToDatabaseSkills(dskill); Save(); Skill skill = new Skill(dskill); SkillsActive.Add(skill.ID, skill); Handler18.SendSkillLearnt(this, skill.ID); //TODO: broadcast the animation of learning to others } } else { Log.WriteLine(LogLevel.Error, "Character tried to use skillbook but ActiveSkill does not exist."); Handler12.SendItemUsed(this, item, 1811); } } else { ItemUseEffectInfo effects; if (!DataProvider.Instance.ItemUseEffects.TryGetValue(item.ItemID, out effects)) { Log.WriteLine(LogLevel.Warn, "Missing ItemUseEffect for ID {0}", item.ItemID); Handler12.SendItemUsed(this, item, 1811); return; } Handler12.SendItemUsed(this, item); //No idea what this does, but normally it's sent. UseOneItemStack(item); foreach (ItemEffect effect in effects.Effects) { switch (effect.Type) { case ItemUseEffectType.AbState: //TOOD: add buffs for itemuse continue; case ItemUseEffectType.HP: HealHP(effect.Value); break; case ItemUseEffectType.SP: HealSP(effect.Value); break; case ItemUseEffectType.ScrollTier: break; default: Log.WriteLine(LogLevel.Warn, "Invalid item effect for ID {0}: {1}", item.ItemID, effect.Type.ToString()); break; } } } } else { Log.WriteLine(LogLevel.Warn, "Invalid item use."); } }
public void UseItem(byte slot) { Item item; if (!this.Inventory.InventoryItems.TryGetValue(slot, out item)) //TODO: not sure about return scrolls { //TODO: send item not found / error occured packet return; } if (item.ItemInfo.Level > Level) { Handler12.SendItemUsed(this, item, 1800); return; } if (((uint)item.ItemInfo.Jobs & (uint)Job) == 0) { Handler12.SendItemUsed(this, item, 1801); return; } if (item.ItemInfo.Type == ItemType.Useable) //potion { if (item.ItemInfo.Class == ItemClass.Scroll) //return scroll { RecallCoordinate coord; MapInfo map; if (DataProvider.Instance.RecallCoordinates.TryGetValue(item.ItemInfo.InxName, out coord) && (map = DataProvider.Instance.MapsByID.Values.First(m => m.ShortName == coord.MapName)) != null) { Handler12.SendItemUsed(this, item); //No idea what this does, but normally it's sent. UseOneItemStack(item); ChangeMap(map.ID, coord.LinkX, coord.LinkY); //TODO: do this properly via world later. } else { Handler12.SendItemUsed(this, item, 1811); } } else if (item.ItemInfo.Class == ItemClass.Mount) { Handler12.SendItemUsed(this, item); /* if (this.Mount == null) { if (item.Mount != null) { this.Mount = item.Mount; this.Mount.Food = item.Mount.Food; this.Mounting(item.Mount.Handle,false); } else { //no mount data found } } else { if (this.Mount != null) { UnMount(); } else if (this.LastUse.Subtract(DateTime.Now).TotalSeconds >= this.Mount.Cooldown) { Zepheus.FiestaLib.Data.Mount mMount = null; if (DataProvider.Instance.MountyByItemID.TryGetValue(item.ID, out mMount)) { this.UnMount(); this.Mount = mMount; this.Mounting(Mount.Handle,false); } } }*/ } else if (item.ItemInfo.Class == ItemClass.MountFood) { if (this.Mount != null) { Mount cMount = null; if (DataProvider.Instance.MountyByItemID.TryGetValue(item.ID, out cMount)) { int newfoodcount = this.Mount.Food += 250; if (cMount.Food >= newfoodcount) { this.Mount.Food = (ushort)newfoodcount; } else { this.Mount.Food = cMount.Food; } this.UpdateMountFood(); } } } else if (item.ItemInfo.Class == ItemClass.SkillBook) { //TODO: passive skills! ActiveSkillInfo info; if (DataProvider.Instance.ActiveSkillsByName.TryGetValue(item.ItemInfo.InxName, out info)) { if (SkillsActive.ContainsKey(info.ID)) { Handler12.SendItemUsed(this, item, 1811); //character has this skill already } else { Handler12.SendItemUsed(this, item); UseOneItemStack(item); DatabaseSkill dskill = new DatabaseSkill(); dskill.Character = Character; dskill.SkillID = (short)info.ID; dskill.IsPassive = false; dskill.Upgrades = 0; Character.SkillList.Add(dskill); Program.CharDBManager.GetClient().ExecuteQuery("INSERT INTO Skillist (ID,Owner,SkillID,Upgrades,IsPassive) VALUES ('" + dskill.ID + "','" + dskill.Character.ID + "','" + dskill.SkillID + "','" + dskill.Upgrades + "','" + Convert.ToInt32(dskill.IsPassive) + "')"); Save(); Skill skill = new Skill(dskill); SkillsActive.Add(skill.ID, skill); Handler18.SendSkillLearnt(this, skill.ID); //TODO: broadcast the animation of learning to others } } else { Log.WriteLine(LogLevel.Error, "Character tried to use skillbook but ActiveSkill does not exist."); Handler12.SendItemUsed(this, item, 1811); } } else { ItemUseEffectInfo effects; if (!DataProvider.Instance.ItemUseEffects.TryGetValue(item.ID, out effects)) { Log.WriteLine(LogLevel.Warn, "Missing ItemUseEffect for ID {0}", item.ID); Handler12.SendItemUsed(this, item, 1811); return; } Handler12.SendItemUsed(this, item); //No idea what this does, but normally it's sent. UseOneItemStack(item); foreach (ItemEffect effect in effects.Effects) { switch (effect.Type) { case ItemUseEffectType.AbState: //TOOD: add buffs for itemuse continue; case ItemUseEffectType.HP: HealHP(effect.Value); break; case ItemUseEffectType.SP: HealSP(effect.Value); break; case ItemUseEffectType.ScrollTier: break; default: Log.WriteLine(LogLevel.Warn, "Invalid item effect for ID {0}: {1}", item.ID, effect.Type.ToString()); break; } } } } else { Log.WriteLine(LogLevel.Warn, "Invalid item use."); } }