private void DoActions(PlayerObject ob, NPCPage page) { foreach (NPCAction action in page.Actions) { switch (action.ActionType) { case NPCActionType.Teleport: if (action.MapParameter1 == null) { return; } Map map = SEnvir.GetMap(action.MapParameter1); if (action.IntParameter1 == 0 && action.IntParameter2 == 0) { ob.Teleport(map, map.GetRandomLocation()); } else { ob.Teleport(map, new Point(action.IntParameter1, action.IntParameter2)); } break; case NPCActionType.TakeGold: ob.Gold -= action.IntParameter1; ob.GoldChanged(); break; case NPCActionType.ChangeElement: UserItem weapon = ob.Equipment[(int)EquipmentSlot.Weapon]; S.ItemStatsChanged result = new S.ItemStatsChanged { GridType = GridType.Equipment, Slot = (int)EquipmentSlot.Weapon, NewStats = new Stats() }; result.NewStats[Stat.WeaponElement] = action.IntParameter1 - weapon.Stats[Stat.WeaponElement]; weapon.AddStat(Stat.WeaponElement, action.IntParameter1 - weapon.Stats[Stat.WeaponElement], StatSource.Refine); weapon.StatsChanged(); ob.RefreshStats(); ob.Enqueue(result); break; case NPCActionType.ChangeHorse: ob.Character.Account.Horse = (HorseType)action.IntParameter1; ob.RemoveMount(); ob.RefreshStats(); if (ob.Character.Account.Horse != HorseType.None) { ob.Mount(); } break; case NPCActionType.GiveGold: long gold = ob.Gold + action.IntParameter1; ob.Gold = (long)gold; ob.GoldChanged(); break; case NPCActionType.Marriage: ob.MarriageRequest(); break; case NPCActionType.Divorce: ob.MarriageLeave(); break; case NPCActionType.RemoveWeddingRing: ob.MarriageRemoveRing(); break; case NPCActionType.GiveItem: if (action.ItemParameter1 == null) { continue; } ItemCheck check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero); if (!ob.CanGainItems(false, check)) { continue; } while (check.Count > 0) { ob.GainItem(SEnvir.CreateFreshItem(check)); } break; case NPCActionType.TakeItem: if (action.ItemParameter1 == null) { continue; } ob.TakeItem(action.ItemParameter1, action.IntParameter1); break; case NPCActionType.ResetWeapon: ob.NPCResetWeapon(); break; case NPCActionType.GiveItemExperience: if (action.ItemParameter1 == null) { continue; } check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero); if (!ob.CanGainItems(false, check)) { continue; } while (check.Count > 0) { UserItem item = SEnvir.CreateFreshItem(check); item.Experience = action.IntParameter2; if (item.Experience >= Globals.AccessoryExperienceList[item.Level]) { item.Experience -= Globals.AccessoryExperienceList[item.Level]; item.Level++; item.Flags |= UserItemFlags.Refinable; } ob.GainItem(item); } break; case NPCActionType.SpecialRefine: ob.NPCSpecialRefine(action.StatParameter1, action.IntParameter1); break; case NPCActionType.Rebirth: if (ob.Level >= 86 + ob.Character.Rebirth) { ob.NPCRebirth(); } break; } } }
private void DoActions(PlayerObject ob, NPCPage page) { foreach (NPCAction action in page.Actions) { switch (action.ActionType) { case NPCActionType.Teleport: if (action.MapParameter1 == null && action.InstanceParameter1 == null) { return; } if (action.InstanceParameter1 != null) { if (ob.CurrentMap.Instance != null) { return; } var index = SEnvir.LoadInstance(action.InstanceParameter1); if (index == null) { return; } ob.Teleport(action.InstanceParameter1.ConnectRegion, action.InstanceParameter1, index.Value); } else { Map map = SEnvir.GetMap(action.MapParameter1); if (action.IntParameter1 == 0 && action.IntParameter2 == 0) { ob.Teleport(map, map.GetRandomLocation()); } else { ob.Teleport(map, new Point(action.IntParameter1, action.IntParameter2)); } } break; case NPCActionType.TakeGold: ob.Gold.Amount -= action.IntParameter1; ob.GoldChanged(); break; case NPCActionType.ChangeElement: UserItem weapon = ob.Equipment[(int)EquipmentSlot.Weapon]; S.ItemStatsChanged result = new S.ItemStatsChanged { GridType = GridType.Equipment, Slot = (int)EquipmentSlot.Weapon, NewStats = new Stats() }; result.NewStats[Stat.WeaponElement] = action.IntParameter1 - weapon.Stats[Stat.WeaponElement]; weapon.AddStat(Stat.WeaponElement, action.IntParameter1 - weapon.Stats[Stat.WeaponElement], StatSource.Refine); weapon.StatsChanged(); ob.RefreshStats(); ob.Enqueue(result); break; case NPCActionType.ChangeHorse: ob.Character.Account.Horse = (HorseType)action.IntParameter1; ob.RemoveMount(); ob.RefreshStats(); if (ob.Character.Account.Horse != HorseType.None) { ob.Mount(); } break; case NPCActionType.GiveGold: long gold = ob.Gold.Amount + action.IntParameter1; ob.Gold.Amount = (long)gold; ob.GoldChanged(); break; case NPCActionType.Marriage: ob.MarriageRequest(); break; case NPCActionType.Divorce: ob.MarriageLeave(); break; case NPCActionType.RemoveWeddingRing: ob.MarriageRemoveRing(); break; case NPCActionType.GiveItem: if (action.ItemParameter1 == null) { continue; } ItemCheck check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero); if (!ob.CanGainItems(false, check)) { continue; } while (check.Count > 0) { ob.GainItem(SEnvir.CreateFreshItem(check)); } break; case NPCActionType.TakeItem: if (action.ItemParameter1 == null) { continue; } ob.TakeItem(action.ItemParameter1, action.IntParameter1); break; case NPCActionType.ResetWeapon: ob.NPCResetWeapon(); break; case NPCActionType.GiveItemExperience: if (action.ItemParameter1 == null) { continue; } check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero); if (!ob.CanGainItems(false, check)) { continue; } while (check.Count > 0) { UserItem item = SEnvir.CreateFreshItem(check); item.Experience = action.IntParameter2; if (item.Experience >= Globals.AccessoryExperienceList[item.Level]) { item.Experience -= Globals.AccessoryExperienceList[item.Level]; item.Level++; item.Flags |= UserItemFlags.Refinable; } ob.GainItem(item); } break; case NPCActionType.SpecialRefine: ob.NPCSpecialRefine(action.StatParameter1, action.IntParameter1); break; case NPCActionType.Rebirth: if (ob.Level >= 86 + ob.Character.Rebirth) { ob.NPCRebirth(); } break; case NPCActionType.GiveCurrency: { if (action.StringParameter1 == null) { continue; } var info = SEnvir.CurrencyInfoList.Binding.FirstOrDefault(x => string.Equals(x.Name, action.StringParameter1, StringComparison.OrdinalIgnoreCase)); if (info == null) { continue; } var userCurrency = ob.GetCurrency(info); var amount = userCurrency.Amount + action.IntParameter1; userCurrency.Amount = amount; ob.CurrencyChanged(userCurrency); } break; case NPCActionType.TakeCurrency: { if (action.StringParameter1 == null) { continue; } var info = SEnvir.CurrencyInfoList.Binding.FirstOrDefault(x => string.Equals(x.Name, action.StringParameter1, StringComparison.OrdinalIgnoreCase)); if (info == null) { continue; } var userCurrency = ob.GetCurrency(info); var amount = userCurrency.Amount - action.IntParameter1; userCurrency.Amount = amount; ob.CurrencyChanged(userCurrency); } break; } } }