public void AddDynaNpc(DynamicNpc npc) { if (GameObjects.TryAdd(npc.Identity, npc)) { npc.Map = this; foreach (Character observer in Players.Values) { if (Calculations.InScreen(observer.MapX, observer.MapY, npc.MapX, npc.MapY)) { observer.Screen.Add(npc); npc.SendSpawnTo(observer); } } } }
public static void Load() { var count = 100000; foreach (var file in Directory.EnumerateFileSystemEntries("RAW\\DynNpcs\\")) { using (var reader = new KeyValueFormat(file)) { var map = reader.Load <int>("Map"); if (map > 5000) { continue; } var obj = new DynamicNpc { UniqueId = count, Type = reader.Load <byte>("Action"), Look = reader.Load <uint>("Look"), MapId = reader.Load <ushort>("Map"), MaximumHp = reader.Load <ushort>("HP"), CurrentHp = reader.Load <ushort>("HP"), Base = reader.Load <byte>("Base"), Sort = reader.Load <byte>("Sort"), Defense = reader.Load <ushort>("Defense"), MagicDefense = reader.Load <ushort>("MDefense") }; UniqueIdGenerator.Goto(obj.UniqueId, EntityType.DynamicNpc); obj.Location.X = reader.Load <ushort>("X"); obj.Location.Y = reader.Load <ushort>("Y"); if (obj.MapId == 0) { continue; } if (GameWorld.Maps.ContainsKey(obj.MapId)) { Collections.Npcs.Add(obj.UniqueId, obj); GameWorld.Maps[obj.MapId].LoadInEntity(obj); } count++; } } ShopDb.LoadShops(); }
public bool Destroy() { m_szWords = ""; if (m_pShop != null && Vending) { m_vending = false; m_pNpc.Vending = false; m_pNpc.Name = ""; m_pMap.RemoveNpc(m_pShop); m_pOwner.Action = EntityAction.STAND; m_pNpc = null; m_pShop = null; } Items.Clear(); return(true); }
public bool Create() { m_pMap = m_pOwner.Map; Items = new ConcurrentDictionary <uint, BoothItem>(); m_pNpc = m_pMap.GameObjects.Values.FirstOrDefault(x => x.MapX == m_pOwner.MapX - 2 && x.MapY == m_pOwner.MapY) as GameNpc; if (m_pNpc == null) { return(false); } if (m_pNpc.Vending) { return(false); } Vending = true; m_szWords = ""; m_pOwner.Direction = FacingDirection.SOUTH_EAST; m_pOwner.Action = EntityAction.SIT; var tempDb = new DbDynamicNPC { Id = ((m_pOwner.Identity % 1000000) + ((m_pOwner.Identity / 1000000) * 100000)), Name = m_pOwner.Name, Cellx = (ushort)(m_pNpc.MapX + 3), Celly = m_pNpc.MapY, Type = NpcTypes.BOOTH_NPC, Lookface = 406, Mapid = m_pOwner.MapIdentity, Datastr = "PlayerShop" }; m_pShop = new DynamicNpc(tempDb) { Name = m_pOwner.Name }; m_dwIdentity = m_pShop.Identity; m_pMap.AddDynaNpc(m_pShop); return(true); }
public bool IsInBase(Character pUser) { foreach (var obj in pUser.Screen.GetAroundRoles) { if (obj is DynamicNpc) { DynamicNpc pNpc = obj as DynamicNpc; if (!pNpc.IsCtfFlag()) { continue; } if (pNpc.GetDistance(pUser) > 10) { continue; } if (pNpc.OwnerType == 2 && pNpc.OwnerIdentity == pUser.SyndicateIdentity) { return(true); } } } return(false); }
private static uint GetActionIdentity(Character pUser, IScreenObject pNpc) { uint idAction = 0; if (pNpc is GameNpc) { GameNpc pGameNpc = pNpc as GameNpc; for (int i = 0; i < 8; i++) { switch (i) { case 0: idAction = pGameNpc.Task0; break; case 1: idAction = pGameNpc.Task1; break; case 2: idAction = pGameNpc.Task2; break; case 3: idAction = pGameNpc.Task3; break; case 4: idAction = pGameNpc.Task4; break; case 5: idAction = pGameNpc.Task5; break; case 6: idAction = pGameNpc.Task6; break; case 7: idAction = pGameNpc.Task7; break; } TaskStruct pTask; if (ServerKernel.GameTasks.TryGetValue(idAction, out pTask)) { bool bItem1 = true, bItem2 = true, bMoney = true, bProf = true, bSex = true, bMinPk = true, bMaxPk = true, bTeam = true, bMetem = true, bMarriage = true; if (pTask.Itemname1 != "") { bItem1 = pUser.Inventory.Items.Values.FirstOrDefault(x => x.Itemtype.Name == pTask.Itemname1) != null; } if (pTask.Itemname2 != "") { bItem2 = pUser.Inventory.Items.Values.FirstOrDefault(x => x.Itemtype.Name == pTask.Itemname2) != null; } if (pTask.Money > 0) { bMoney = pUser.Silver >= pTask.Money; } if (pTask.Profession > 0) { if (pTask.Profession > 9) { bProf = pUser.Profession / 10 == pTask.Profession; } else { bProf = pUser.Profession == pTask.Profession; } } if (pTask.Sex > 0 && pTask.Sex < 999) { bSex = pUser.Gender == pTask.Sex; } bMinPk = pUser.PkPoints >= pTask.MinPk; bMaxPk = pUser.PkPoints <= pTask.MaxPk; if (pTask.Team != 0 && pTask.Team != 999) { bTeam = pUser.Team != null; } if (pTask.Metempsychosis > 0) { bMetem = pUser.Metempsychosis >= pTask.Metempsychosis; } if (pTask.Marriage > 0) { bMarriage = pUser.Mate != "None"; } bool bRet = bItem1 && bItem2 && bMoney && bProf && bSex && bMinPk && bMaxPk && bTeam && bMetem && bMarriage; if (bRet) { idAction = pTask.IdNext; break; } if (!bRet && pTask.IdNextfail != 0) { idAction = pTask.IdNextfail; break; } } } } else if (pNpc is DynamicNpc) { DynamicNpc pGameNpc = pNpc as DynamicNpc; for (int i = 0; i < 8; i++) { switch (i) { case 0: idAction = pGameNpc.Task0; break; case 1: idAction = pGameNpc.Task1; break; case 2: idAction = pGameNpc.Task2; break; case 3: idAction = pGameNpc.Task3; break; case 4: idAction = pGameNpc.Task4; break; case 5: idAction = pGameNpc.Task5; break; case 6: idAction = pGameNpc.Task6; break; case 7: idAction = pGameNpc.Task7; break; } TaskStruct pTask; if (ServerKernel.GameTasks.TryGetValue(idAction, out pTask)) { bool bItem1 = true, bItem2 = true, bMoney = true, bProf = true, bSex = true, bMinPk = true, bMaxPk = true, bTeam = true, bMetem = true, bMarriage = true; if (pTask.Itemname1 != "") { bItem1 = pUser.Inventory.Items.Values.FirstOrDefault(x => x.Itemtype.Name == pTask.Itemname1) != null; } if (pTask.Itemname2 != "") { bItem2 = pUser.Inventory.Items.Values.FirstOrDefault(x => x.Itemtype.Name == pTask.Itemname2) != null; } if (pTask.Money > 0) { bMoney = pUser.Silver >= pTask.Money; } if (pTask.Profession > 0) { if (pTask.Profession > 9) { bProf = pUser.Profession / 10 == pTask.Profession; } else { bProf = pUser.Profession == pTask.Profession; } } if (pTask.Sex > 0 && pTask.Sex < 999) { bSex = pUser.Gender == pTask.Sex; } bMinPk = pUser.PkPoints >= pTask.MinPk; bMaxPk = pUser.PkPoints <= pTask.MaxPk; if (pTask.Team != 0 && pTask.Team != 999) { bTeam = pUser.Team != null; } if (pTask.Metempsychosis > 0) { bMetem = pUser.Metempsychosis >= pTask.Metempsychosis; } if (pTask.Marriage > 0) { bMarriage = pUser.Mate != "None"; } bool bRet = bItem1 && bItem2 && bMoney && bProf && bSex && bMinPk && bMaxPk && bTeam && bMetem && bMarriage; if (bRet) { idAction = pTask.IdNext; break; } if (!bRet && pTask.IdNextfail != 0) { idAction = pTask.IdNextfail; break; } } } } return(idAction); }
public bool ProcAttack_Hand2Hand() { try { if (m_pOwner == null || m_dwTargetId == 0 || !IsBattleMaintain()) { ResetBattle(); return(false); } } catch (Exception ex) { ServerKernel.Log.SaveLog("ProcAttack_Hand2Hand.IsBattleMaint", false, LogType.WARNING); ServerKernel.Log.SaveLog(ex.ToString(), false, LogType.EXCEPTION); return(false); } var pTarget = FindRole(m_dwTargetId); if (pTarget == null) { ResetBattle(); return(false); } if (m_pOwner.IsImmunity(pTarget)) { ResetBattle(); return(false); } Character pOwner = null; if (m_pOwner is Character) { pOwner = m_pOwner as Character; } if (IsTargetDodged(m_pOwner, pTarget)) { m_pOwner.SendDamageMsg(pTarget.Identity, 0, InteractionEffect.NONE); return(true); } // if archer //if (m_pOwner.IsBowman()) //{ // if (pOwner != null) // { // if (!pOwner.Equipment.Items.ContainsKey(5) || !pOwner.Equipment.Items[5].IsArrowSort() // || pOwner.Equipment.Items[5].Durability <= 0) // { // if (!pOwner.ReloadArrows()) // { // ResetBattle(); // return false; // no arrows // } // } // else // { // pOwner.Equipment.Items[5].Durability -= 1; // } // pOwner.Send(pOwner.Equipment.Items[5].InformationPacket(true)); // } //} if (QueryMagic() != null) { QueryMagic().AbortMagic(true); } if (pTarget is Character) { Character pTargetUser = pTarget as Character; if (pTargetUser.CheckScapegoat(m_pOwner)) { return(true); } } if (m_pOwner is Character && m_pOwner.AutoSkillAttack(pTarget)) { return(true); } InteractionEffect special = InteractionEffect.NONE; int nDamage = m_pOwner.Attack(pTarget, ref special); int nTargetLifeLost = Math.Max(1, nDamage); int nExp = (int)Math.Min(pTarget.MaxLife, nTargetLifeLost); if (m_pOwner.QueryStatus(FlagInt.FATAL_STRIKE) != null && pTarget is Monster) { Monster pMob = pTarget as Monster; if (!pMob.IsGuard() && !pMob.IsPlayer() && !pMob.IsDynaNpc() && !pMob.IsDynaMonster()) { m_pOwner.MapX = pTarget.MapX; m_pOwner.MapY = pTarget.MapY; var msg = new MsgAction(m_pOwner.Identity, pTarget.Identity, m_pOwner.MapX, m_pOwner.MapY, GeneralActionType.NINJA_STEP); m_pOwner.Send(msg); m_pOwner.Screen.SendMovement(msg); } } m_pOwner.SendDamageMsg(pTarget.Identity, (uint)nTargetLifeLost, special); if (nDamage == 0) { return(false); } // pTarget.AddAttribute(ClientUpdateType.HITPOINTS, -1*nTargetLifeLost, true); pTarget.BeAttack(0, m_pOwner, nDamage, true); // Syn rank DynamicNpc pNpc = null; Character pOwnerUser = null; if (pTarget is DynamicNpc) { pNpc = pTarget as DynamicNpc; } if (m_pOwner is Character) { pOwnerUser = m_pOwner as Character; } if (pNpc != null && pOwnerUser != null && pNpc.IsAwardScore()) { if (pNpc.IsCtfFlag()) { pOwnerUser.AwardCtfScore(pNpc, nTargetLifeLost); } else { pOwnerUser.AwardSynWarScore(pNpc, nTargetLifeLost); } } if (m_pOwner is Character && pNpc != null && pNpc.IsGoal() || pTarget.IsMonster()) // check is monster { nExp = m_pOwner.AdjustExperience(pTarget, nExp, false); int nAdditionExp = 0; if (!pTarget.IsAlive) { nAdditionExp = (int)(pTarget.MaxLife * 5 / 100); nExp += nAdditionExp; if (pOwnerUser != null) { if (pOwnerUser.Team != null) { pOwnerUser.Team.AwardMemberExp(pOwnerUser.Identity, pTarget, nAdditionExp); } } } m_pOwner.AwardBattleExp(nExp, true); if (!pTarget.IsAlive && nAdditionExp > 0) { if (!pTarget.IsAlive && !m_pOwner.Map.IsTrainingMap() && pOwnerUser != null) { pOwnerUser.Send(string.Format(ServerString.STR_KILLING_EXPERIENCE, nAdditionExp), ChatTone.TOP_LEFT); } } if (pOwnerUser != null) { Item item; if (pOwnerUser.Equipment.Items.TryGetValue(ItemPosition.RIGHT_HAND, out item)) { pOwnerUser.WeaponSkill.AwardExperience((ushort)item.GetItemSubtype(), nExp); } if (pOwnerUser.Equipment.Items.TryGetValue(ItemPosition.LEFT_HAND, out item)) { pOwnerUser.WeaponSkill.AwardExperience((ushort)item.GetItemSubtype(), nExp); } } } m_pOwner.AdditionMagic(nTargetLifeLost, nDamage); if (Calculations.ChanceCalc(5f) && m_pOwner is Character) { (m_pOwner as Character).SendWeaponMagic2(pTarget); } if (!pTarget.IsAlive) { int dwDieWay = m_pOwner.IsSimpleMagicAtk() ? 3 : 1; if (nDamage > pTarget.MaxLife / 3) { dwDieWay = 2; } m_pOwner.Kill(pTarget, m_pOwner.IsBowman() ? 5 : (uint)dwDieWay); } if (pOwnerUser != null && pOwnerUser.QueryStatus(FlagInt.FATAL_STRIKE) != null) { DestroyAutoAttack(); } return(true); }
public void OnTimer() { if (m_pState == SyndicateWarState.NOT_BUILT) { return; } int now = int.Parse(DateTime.Now.ToString("HHmmss")); if (m_pState == SyndicateWarState.NOT_RUNNING && (now >= _STARTUP_TIME && now < _END_TIME)) { // start foreach (var syn in m_pSynPoints.Values) { syn.Value1 = 0; m_pRepo.SaveOrUpdate(syn); } foreach (var user in m_pUserPoints.Values) { user.Value1 = 0; m_pRepo.SaveOrUpdate(user); } IScreenObject pScrObj; if (m_pMainMap.GameObjects.TryGetValue(920, out pScrObj) && pScrObj is DynamicNpc) { DynamicNpc pNpc = pScrObj as DynamicNpc; pNpc.Life = pNpc.MaxLife; pNpc.SendToRange(); } m_tRank.Startup(10); m_pState = SyndicateWarState.RUNNING; } else if (m_pState == SyndicateWarState.RUNNING && (now >= _STARTUP_TIME && now < _END_TIME)) { // running if (m_tRank.IsActive() && m_tRank.ToNextTime()) { List <string> pRank = new List <string>(9); pRank.Add("Syndicate Score War"); int count = 0; foreach (var rnk in m_pSynPoints.Values.OrderByDescending(x => x.Value1)) { if (rnk.Value1 > 0) { if (count++ < 8) { pRank.Add(string.Format("Nº{0}. {1,16} - {2}", count, rnk.ObjectName.PadRight(16), rnk.Value1)); } else { break; } } } foreach (var player in m_pMainMap.Players.Values.ToList()) { player.Send(pRank[0], ChatTone.EVENT_RANKING); for (int i = 1; i < pRank.Count; i++) { player.Send(pRank[i], ChatTone.EVENT_RANKING_NEXT); } } } } else if (m_pState == SyndicateWarState.RUNNING && (now < _STARTUP_TIME || now > _END_TIME)) { // prepare to finish ServerKernel.SendMessageToAll(string.Format("The time is up! The Guild Score War is over."), ChatTone.TOP_LEFT); m_pState = SyndicateWarState.ENDING; } else if (m_pState == SyndicateWarState.ENDING) { // end time int rank = 0; foreach (var syn in m_pSynPoints.Values.OrderByDescending(x => x.Value1)) { if (rank++ >= 4) { break; } uint synId = syn.ObjectIdentity; int deliverMoney = 0; int deliverEmoney = 0; uint totalMoney = ServerKernel.SYN_SCORE_MONEY_REWARD[rank - 1]; uint totalEmoney = ServerKernel.SYN_SCORE_EMONEY_REWARD[rank - 1]; foreach (var user in m_pUserPoints.Values.Where(x => x.ObjectIdentity == synId && x.PlayerIdentity > 0) .OrderByDescending(x => x.Value1)) { float nPercent = (user.Value1 / (float)syn.Value1); int money = (int)(totalMoney * nPercent); int emoney = (int)(totalEmoney * nPercent); deliverMoney += money; deliverEmoney += emoney; if (money <= 0 && emoney <= 0) { continue; } Client pClient; if (ServerKernel.Players.TryGetValue(user.PlayerIdentity, out pClient)) { pClient.Character.AwardMoney(money); pClient.Character.AwardEmoney(emoney); pClient.SendMessage(string.Format(ServerString.STR_SSPK_AWARDED_PRIZE, user.Value1, money, emoney), ChatTone.GUILD); } else { DbUser pUser = Database.Characters.SearchByIdentity(user.PlayerIdentity); if (pUser != null) { pUser.Money = (uint)Math.Min(int.MaxValue, pUser.Money + money); pUser.Emoney = (uint)Math.Min(int.MaxValue, pUser.Emoney + emoney); Database.Characters.SaveOrUpdate(pUser); } } } } ServerKernel.SendMessageToAll(string.Format("The Guild Score War is over."), ChatTone.TALK); m_pState = SyndicateWarState.NOT_RUNNING; } }