public void SetCreatureData(CreatureData data) { creatureData = data; gameObject.name = creatureData.name; health = creatureData.maxHealth; libido = 100; // Hardcoded default for now. }
public static CreatureData Merge(CreatureData data1, CreatureData data2) { CreatureData newData = new CreatureData(); if (Random.value < 0.5f) { newData.BodyId = data1.BodyId; Debug.Log(newData.BodyId); newData.CloneRate = Mutate(data1.CloneRate); } else { newData.BodyId = data2.BodyId; Debug.Log(newData.BodyId); newData.CloneRate = Mutate(data2.CloneRate); } if (Random.value < 0.5f) { newData.HeadId = data1.HeadId; Debug.Log(newData.HeadId); newData.SicknessRate = Mutate(data1.SicknessRate); } else { newData.HeadId = data2.HeadId; Debug.Log(newData.HeadId); newData.SicknessRate = Mutate(data2.SicknessRate); } newData.initialized = true; return newData; }
public void SetData(CreatureData _data) { data = _data; bodyRenderer.sprite = bodySprites[data.BodyId]; headRenderer.sprite = headSprites[data.HeadId]; timeToClone = data.CloneRate; }
void NewCreature(CreatureData data) { GameObject creatureGO = GameObject.Instantiate(creaturePrefav) as GameObject; Creature creature = creatureGO.GetComponent<Creature> (); creature.SetData(data); creatureGO.transform.parent = transform.parent; creatureGO.transform.position = transform.position; }
public static CreatureData MooseData() { CreatureData newData = new CreatureData(); newData.BodyId = 0; newData.HeadId = 0; newData.CloneRate = Mutate(10.0f); newData.SicknessRate = Mutate(0.01f); newData.initialized = true; return newData; }
public static CreatureData GekoData() { CreatureData newData = new CreatureData(); newData.BodyId = 2; newData.HeadId = 2; newData.CloneRate = Mutate(15.4f); newData.SicknessRate = Mutate(0.05f); newData.initialized = true; return newData; }
public static CreatureData DolphinData() { CreatureData newData = new CreatureData(); newData.BodyId = 1; newData.HeadId = 1; newData.CloneRate = Mutate(20.0f); newData.SicknessRate = Mutate(0.3f); newData.initialized = true; return newData; }
public Target(CreatureData c, FightActions action, byte priority, FightSecurity security, FightStances stance, Attack attackMode, Follow followMode) : base(c.Name, c.HitPoints, c.ExperiencePoints, c.SummonMana, c.ConvinceMana, c.MaxDamage, c.CanIllusion, c.CanSeeInvisible, c.FrontAttack, c.Immunities, c.Strengths, c.Weaknesses, c.Sounds, c.Loot) { this.Action = action; this.Priority = priority; this.Security = security; this.Stance = stance; this.AttackMode = attackMode; this.FollowMode = followMode; this.Extra = new List<FightExtraPair>(); }
public Sprite GetCreatureSprite(CreatureData data) { string path = "Sprites/" + data.Type.ToString() + "/" + data.Name; path = path.ToLower(); if (spritesDictionary.ContainsKey(path)) { return(spritesDictionary[path]); } else { var sprite = Resources.Load <Sprite>(path) as Sprite; if (sprite != null) { spritesDictionary.Add(path, sprite); return(sprite); } } return(spritesDictionary[defaultImageName]); }
public void Load(CreatureData creature) { if (Current != creature) { Current = creature; foreach (var prefab in SkillLinks.Values.ToList()) { Destroy(prefab.gameObject); } SkillLinks = new Dictionary <Skill, SkillDisplay>(); foreach (var skill in Current.Skills) { var skillDisplay = Instantiate(SkillPrefab, transform); skillDisplay.Load(skill); SkillLinks.Add(skill, skillDisplay); } } }
public void Load(CreatureData creature) { if (Current != creature) { Current = creature; foreach (var prefab in NeedProgressLinks.Values.ToList()) { Destroy(prefab.gameObject); } NeedProgressLinks = new Dictionary <NeedBase, TitledProgressBar>(); foreach (var need in Current.Needs) { var bar = Instantiate(ProgressBarPrefab, transform); bar.Load(need.Name, need.Current / need.Max, need.Name, need.GetDescription()); NeedProgressLinks.Add(need, bar); } } }
public GameSaveData(IEnumerable <Criatura> criaturas, PlayerMovement player, int gems, CalendarSystem calendarSystem) { this.player = new PlayerData(player); this.gems = gems; this.startTime = calendarSystem.startTime + Time.timeSinceLevelLoad; creatures = new List <CreatureData>(); foreach (var c in criaturas) { creatures.Add(new CreatureData(c)); } Combinator combinator = GameObject.FindObjectOfType <Combinator>(); if (combinator.criatura1) { combinatorCreature1 = new CreatureData(combinator.criatura1); } if (combinator.criatura2) { combinatorCreature2 = new CreatureData(combinator.criatura2); } Analyzer analyzer = GameObject.FindObjectOfType <Analyzer>(); if (analyzer.criatura1) { analyzerCreature = new CreatureData(analyzer.criatura1); } Harvester harvester = GameObject.FindObjectOfType <Harvester>(); if (harvester.criatura1) { harvesterCreature = new CreatureData(harvester.criatura1); } }
public void LoadCreature() { CreatureData data = SaveSystem.LoadValues(); Name = data.Name; if (data.form.Equals("normal")) { form = Form.normal; } else if (data.form.Equals("upright")) { form = Form.upright; } else { form = Form.reveral; } maxHP = data.maxHP; HP = data.HP; Dfn = data.Dfn; Atk = data.Atk; for (int i = 0; i < data.skill_count; i++) { if (data.skills[i] == "Attack") { skills.Add(new Attack()); } else if (data.skills[i] == "Scales of Justice") { skills.Add(new ScalesOfJustice()); } else if (data.skills[i] == "Reversal") { skills.Add(new ReversalJustice()); } } }
private void SpawnCreature(CreatureData newCreature) { refr = Instantiate(_cContainer, Vector3.zero, Quaternion.identity, transform); AIController _aic = refr.GetComponent <AIController>(); Transform _child = refr.transform.GetChild(0); DragDropCreature _ddc = _child.GetComponent <DragDropCreature>(); _aic._creatureID = currCreatureID; _aic._creatureData = newCreature; _aic.SceneBounds = this.SceneBounds; currCreatureID++; _child.transform.position = FindRandomPos(SceneBounds); _child.GetComponent <SpriteRenderer>().sprite = newCreature.CreatureImage; _ddc._cData = newCreature; refr.name = _aic._creatureData.CreatureName + " - " + _aic._creatureID.ToString(); _creatures.Add(refr); Debug.Log("Spawned: " + newCreature.CreatureName + " - " + _aic._creatureID); }
public FDCreature(int creatureId, CreatureFaction faction, CreatureDefinition definition, FDPosition position) { this.Faction = faction; this.Data = new CreatureData(); this.Data = CreatureData.FromDefinition(creatureId, definition); this.Definition = definition; this.Position = position; this.PreMovePosition = position; this.Data.LastGainedExperience = 0; if (this.Definition.Occupation == 154 || this.Definition.Occupation == 155 || this.Definition.DefinitionId == 747) { this.Data.AIType = CreatureData.AITypes.AIType_Defensive; } else { this.Data.AIType = CreatureData.AITypes.AIType_Aggressive; } }
public void CombineCreatures() { AudioManager._instance.PlaySound(1); if (slotA._slotCreature != null && slotB._slotCreature != null) { CreatureData cdA = slotA._slotCreature.GetComponent <AIController>()._creatureData; CreatureData cdB = slotB._slotCreature.GetComponent <AIController>()._creatureData; foreach (Evolution evo in _evoList.EvoList) { if (evo.Creature01 == cdA && evo.Creature02 == cdB || evo.Creature01 == cdB && evo.Creature02 == cdA) { ProduceNewCreature(evo.ResultCreature); _pData.RemoveCreature(cdA); _pData.RemoveCreature(cdB); ClearSlots(true); } } ClearSlots(false); } }
public override bool Done(CreatureData creature) { if (creature.UnableToFindPath) { // clear unable to find variable to ensure we can move again creature.UnableToFindPath = false; throw new TaskFailedException("Unable to find path, cancel move."); } if (!creature.TargetCoordinate.x.AlmostEquals(TargetX) || !creature.TargetCoordinate.z.AlmostEquals(TargetZ)) { creature.SetTargetCoordinate(TargetX, TargetZ); } if (creature.X == TargetX && creature.Z == TargetZ) { // dynamic map expansion // Loc.GetMap().ExpandChunksAround(creature.Cell); creature.SetAnimation(AnimationType.Idle); return(true); } return(false); }
public void Add(ICreature_Script creature) { m_overData = null; m_captureData = creature.GetData(); for (int i = 0; i < m_list.DataList.Length; i++) { if (m_list.DataList[i].drumonName.Equals("")) { m_list.DataList[i].drumonName = creature.GetData().drumonName; m_list.DataList[i].level = creature.GetData().level; m_list.DataList[i].hp = creature.GetData().hp; m_list.DataList[i].maxHp = creature.GetData().maxHp; m_list.DataList[i].atk = creature.GetData().atk; m_list.DataList[i].def = creature.GetData().def; m_list.DataList[i].waitTime = creature.GetData().waitTime; m_list.DataList[i].elem = creature.GetData().elem; m_list.DataList[i].exp = creature.GetData().exp; return; } } m_overData = creature.GetData(); }
public override bool Done(CreatureData creature) { if (SubTasksComplete(creature)) { if (string.IsNullOrEmpty(ContainerId)) { FindContainer(creature); } var container = ContainerId.GetStructure() as LiquidContainer; if (!creature.InRangeOf(container)) { AddSubTask(new Move(container.GetWorkCell())); return(false); } var water = Loc.GetItemController().SpawnItem("StoredWater", creature.Cell, 1); creature.PickUpItem(water, 1); container.FillLevel -= 1; return(true); } return(false); }
public override Task Battlecry(GameHandler gameHandler, int curPlayer, int enemy) { this._keywords = gameHandler.players[curPlayer].creatureData.DeepCopy(); this.writtenEffect = "Aftermath: Gain "; this._aftermathMsg = $"Your {this.name} gives you "; bool checkedFirst = false; foreach (var kw in _keywords.staticKeywords) { if (kw.Value != 0) { if (!checkedFirst) { writtenEffect += $"{kw.Key} x{kw.Value}"; _aftermathMsg += $"{kw.Key} x{kw.Value}"; } else { writtenEffect += $", {kw.Key} x{kw.Value}"; _aftermathMsg += $", {kw.Key} x{kw.Value}"; } checkedFirst = true; } } writtenEffect += "."; _aftermathMsg += "."; if (!checkedFirst) { writtenEffect = string.Empty; _aftermathMsg = string.Empty; } return(Task.CompletedTask); }
public void RetrieveCreatureData() { foreach (List <CatalogData> data in Catalog.current.data) { foreach (CatalogData _data in data) { if (_data is CreatureData) { CreatureData _creatureData = _data as CreatureData; creatureDatas.Add(_creatureData); if (_creatureData.id == module.allyCreatureId) { allyData = _creatureData; } if (_creatureData.id == module.enemyCreatureId) { enemyData = _creatureData; } } } } if (allyData == null) { Debug.LogError("No ally data found!"); allyData = creatureDatas[0]; } if (enemyData == null) { Debug.LogError("No enemy data found!"); enemyData = creatureDatas[0]; } }
public override bool Done(CreatureData creature) { if (SubTasksComplete(creature)) { if (creature.HeldItem?.IsType("Water") == true) { return(true); } else { if (FactionHasWaterContainerWithWater(creature)) { AddSubTask(new GetWaterFromContainer()); } else { AddSubTask(new GetWaterFromSource()); } return(false); } } return(false); }
// void FixedUpdate() {} private void SetupPlayerCreatureData(GameObject creature, int index) { CreatureBattleAI _bai = creature.GetComponent <CreatureBattleAI>(); _bai._entityType = CreatureBattleAI.EntityType.player; CreatureData _cData = _bs._selectablePartners[index]; // Data _bai._maxHealth = (float)_cData.CreatureStats[0]; _bai._dmgStat = (float)_cData.CreatureStats[1]; _bai._knockback = (float)_cData.CreatureStats[2]; _bai._moveSpeed = (float)_cData.CreatureStats[3]; _bai._spdStat = ((float)_cData.CreatureStats[4]) / 100; // float test1 = Random.Range(200f, 500f); // float test2 = Random.Range(0.25f, 0.8f); SpriteRenderer cSprite = creature.GetComponent <SpriteRenderer>(); cSprite.sprite = _cData.CreatureImage; creature.name = _cData.CreatureName + " (P)"; }
public override bool Done(CreatureData creature) { try { if (SubTasksComplete(creature)) { if (MoveToShore(creature)) { var water = Loc.GetItemController().SpawnItem("FreshWater", creature.Cell, 1); creature.PickUpItem(water, 1); return(true); } } } catch (TaskFailedException) { if (_targetShore != null) { _targetShore = null; } } return(false); }
public void LoadConversationTemplates() { _conversationActorTemplateStorage.Clear(); _conversationLineTemplateStorage.Clear(); _conversationTemplateStorage.Clear(); Dictionary <uint, ConversationActorTemplate[]> actorsByConversation = new Dictionary <uint, ConversationActorTemplate[]>(); Dictionary <uint, ulong[]> actorGuidsByConversation = new Dictionary <uint, ulong[]>(); SQLResult actorTemplates = DB.World.Query("SELECT Id, CreatureId, CreatureModelId FROM conversation_actor_template"); if (!actorTemplates.IsEmpty()) { uint oldMSTime = Time.GetMSTime(); do { uint id = actorTemplates.Read <uint>(0); ConversationActorTemplate conversationActor = new ConversationActorTemplate(); conversationActor.Id = id; conversationActor.CreatureId = actorTemplates.Read <uint>(1); conversationActor.CreatureModelId = actorTemplates.Read <uint>(2); _conversationActorTemplateStorage[id] = conversationActor; }while (actorTemplates.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} Conversation actor templates in {1} ms", _conversationActorTemplateStorage.Count, Time.GetMSTimeDiffToNow(oldMSTime)); } else { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation actor templates. DB table `conversation_actor_template` is empty."); } SQLResult lineTemplates = DB.World.Query("SELECT Id, StartTime, UiCameraID, ActorIdx, Unk FROM conversation_line_template"); if (!lineTemplates.IsEmpty()) { uint oldMSTime = Time.GetMSTime(); do { uint id = lineTemplates.Read <uint>(0); if (!CliDB.ConversationLineStorage.ContainsKey(id)) { Log.outError(LogFilter.Sql, "Table `conversation_line_template` has template for non existing ConversationLine (ID: {0}), skipped", id); continue; } ConversationLineTemplate conversationLine = new ConversationLineTemplate(); conversationLine.Id = id; conversationLine.StartTime = lineTemplates.Read <uint>(1); conversationLine.UiCameraID = lineTemplates.Read <uint>(2); conversationLine.ActorIdx = lineTemplates.Read <ushort>(3); conversationLine.Unk = lineTemplates.Read <ushort>(4); _conversationLineTemplateStorage[id] = conversationLine; }while (lineTemplates.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} Conversation line templates in {1} ms", _conversationLineTemplateStorage.Count, Time.GetMSTimeDiffToNow(oldMSTime)); } else { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation line templates. DB table `conversation_line_template` is empty."); } SQLResult actorResult = DB.World.Query("SELECT ConversationId, ConversationActorId, ConversationActorGuid, Idx FROM conversation_actors"); if (!actorResult.IsEmpty()) { uint oldMSTime = Time.GetMSTime(); uint count = 0; do { uint conversationId = actorResult.Read <uint>(0); uint actorId = actorResult.Read <uint>(1); ulong actorGuid = actorResult.Read <ulong>(2); ushort idx = actorResult.Read <ushort>(3); if (actorId != 0 && actorGuid != 0) { Log.outError(LogFilter.Sql, $"Table `conversation_actors` references both actor (ID: {actorId}) and actorGuid (GUID: {actorGuid}) for Conversation {conversationId}, skipped."); continue; } if (actorId != 0) { ConversationActorTemplate conversationActorTemplate = _conversationActorTemplateStorage.LookupByKey(actorId); if (conversationActorTemplate != null) { if (!actorsByConversation.ContainsKey(conversationId)) { actorsByConversation[conversationId] = new ConversationActorTemplate[idx + 1]; } ConversationActorTemplate[] actors = actorsByConversation[conversationId]; if (actors.Length <= idx) { Array.Resize(ref actors, idx + 1); } actors[idx] = conversationActorTemplate; ++count; } else { Log.outError(LogFilter.Sql, "Table `conversation_actors` references an invalid actor (ID: {0}) for Conversation {1}, skipped", actorId, conversationId); } } else if (actorGuid != 0) { CreatureData creData = Global.ObjectMgr.GetCreatureData(actorGuid); if (creData != null) { if (!actorGuidsByConversation.ContainsKey(conversationId)) { actorGuidsByConversation[conversationId] = new ulong[idx + 1]; } var guids = actorGuidsByConversation[conversationId]; if (guids.Length <= idx) { Array.Resize(ref guids, idx + 1); } guids[idx] = actorGuid; ++count; } else { Log.outError(LogFilter.Sql, $"Table `conversation_actors` references an invalid creature guid (GUID: {actorGuid}) for Conversation {conversationId}, skipped"); } } }while (actorResult.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} Conversation actors in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); } else { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation actors. DB table `conversation_actors` is empty."); } SQLResult templateResult = DB.World.Query("SELECT Id, FirstLineId, LastLineEndTime, ScriptName FROM conversation_template"); if (!templateResult.IsEmpty()) { uint oldMSTime = Time.GetMSTime(); do { ConversationTemplate conversationTemplate = new ConversationTemplate(); conversationTemplate.Id = templateResult.Read <uint>(0); conversationTemplate.FirstLineId = templateResult.Read <uint>(1); conversationTemplate.LastLineEndTime = templateResult.Read <uint>(2); conversationTemplate.ScriptId = Global.ObjectMgr.GetScriptId(templateResult.Read <string>(3)); conversationTemplate.Actors = actorsByConversation[conversationTemplate.Id].ToList(); conversationTemplate.ActorGuids = actorGuidsByConversation[conversationTemplate.Id].ToList(); ConversationLineRecord currentConversationLine = CliDB.ConversationLineStorage.LookupByKey(conversationTemplate.FirstLineId); if (currentConversationLine == null) { Log.outError(LogFilter.Sql, "Table `conversation_template` references an invalid line (ID: {0}) for Conversation {1}, skipped", conversationTemplate.FirstLineId, conversationTemplate.Id); } while (currentConversationLine != null) { ConversationLineTemplate conversationLineTemplate = _conversationLineTemplateStorage.LookupByKey(currentConversationLine.Id); if (conversationLineTemplate != null) { conversationTemplate.Lines.Add(conversationLineTemplate); } else { Log.outError(LogFilter.Sql, "Table `conversation_line_template` has missing template for line (ID: {0}) in Conversation {1}, skipped", currentConversationLine.Id, conversationTemplate.Id); } if (currentConversationLine.NextLineID == 0) { break; } currentConversationLine = CliDB.ConversationLineStorage.LookupByKey(currentConversationLine.NextLineID); } _conversationTemplateStorage[conversationTemplate.Id] = conversationTemplate; }while (templateResult.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} Conversation templates in {1} ms", _conversationTemplateStorage.Count, Time.GetMSTimeDiffToNow(oldMSTime)); } else { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation templates. DB table `conversation_template` is empty."); } }
public override void UpdateAI(uint diff) { //Waypoint Updating if (HasEscortState(EscortState.Escorting) && !me.IsEngaged() && !HasEscortState(EscortState.Returning)) { if (_pauseTimer <= diff) { if (!HasEscortState(EscortState.Paused)) { _pauseTimer = 0; if (_ended) { _ended = false; me.GetMotionMaster().MoveIdle(); if (_despawnAtEnd) { Log.outDebug(LogFilter.Scripts, "EscortAI.UpdateAI: reached end of waypoints, despawning at end"); if (_returnToStart) { Position respawnPosition = new Position(); float orientation; me.GetRespawnPosition(out respawnPosition.posX, out respawnPosition.posY, out respawnPosition.posZ, out orientation); respawnPosition.SetOrientation(orientation); me.GetMotionMaster().MovePoint(EscortPointIds.Home, respawnPosition); Log.outDebug(LogFilter.Scripts, $"EscortAI.UpdateAI: returning to spawn location: {respawnPosition}"); } else if (_instantRespawn) { me.Respawn(); } else { me.DespawnOrUnsummon(); } } Log.outDebug(LogFilter.Scripts, "EscortAI.UpdateAI: reached end of waypoints"); RemoveEscortState(EscortState.Escorting); return; } if (!_started) { _started = true; me.GetMotionMaster().MovePath(_path, false); } else if (_resume) { _resume = false; IMovementGenerator movementGenerator = me.GetMotionMaster().GetMotionSlot(MovementSlot.Idle); if (movementGenerator != null) { movementGenerator.Resume(0); } } } } else { _pauseTimer -= diff; } } //Check if player or any member of his group is within range if (_despawnAtFar && HasEscortState(EscortState.Escorting) && !_playerGUID.IsEmpty() && !me.GetVictim() && !HasEscortState(EscortState.Returning)) { if (_playerCheckTimer <= diff) { if (!IsPlayerOrGroupInRange()) { Log.outDebug(LogFilter.Scripts, "EscortAI failed because player/group was to far away or not found"); bool isEscort = false; CreatureData creatureData = me.GetCreatureData(); if (creatureData != null) { isEscort = (WorldConfig.GetBoolValue(WorldCfg.RespawnDynamicEscortNpc) && creatureData.spawnGroupData.flags.HasAnyFlag(SpawnGroupFlags.EscortQuestNpc)); } if (_instantRespawn && !isEscort) { me.DespawnOrUnsummon(0, TimeSpan.FromSeconds(1)); } else if (_instantRespawn && isEscort) { me.GetMap().RemoveRespawnTime(SpawnObjectType.Creature, me.GetSpawnId(), true); } else { me.DespawnOrUnsummon(); } return; } _playerCheckTimer = 1000; } else { _playerCheckTimer -= diff; } } UpdateEscortAI(diff); }
public abstract bool Done(CreatureData creature);
public void AddTarget(string name) { CreatureData c = null; if (CreatureLists.AllCreatures.ContainsKey(name)) { c = CreatureLists.AllCreatures[name]; } else { c = new CreatureData(name, 0, 0, 0, 0, 0, false, false, FrontAttack.None, null, null, null, null, null); } Targets.Add(new Target(c)); }
public string GetBestMageSpell(CreatureData creatureData) { return GetBestMageSpell(creatureData, "exori mort", "exori tera", "exori vis", "exori flam", "exori frigo"); }
public string GetBestPaladinSpell(CreatureData creatureData) { return(GetBestPaladinSpell(creatureData, "exori san", "exori con")); }
public override void Initialize(CreatureData _data) { base.Initialize(_data); }
// Called when the creature tries to spawn. Return false to block spawn and re-evaluate on next tick. public virtual bool CanSpawn(ulong spawnId, uint entry, CreatureTemplate baseTemplate, CreatureTemplate actTemplate, CreatureData cData, Map map) { return(true); }
public void LoadFromDB() { // Pool templates { uint oldMSTime = Time.GetMSTime(); SQLResult result = DB.World.Query("SELECT entry, max_limit FROM pool_template"); if (result.IsEmpty()) { mPoolTemplate.Clear(); Log.outInfo(LogFilter.ServerLoading, "Loaded 0 object pools. DB table `pool_template` is empty."); return; } uint count = 0; do { uint pool_id = result.Read <uint>(0); PoolTemplateData pPoolTemplate = new PoolTemplateData(); pPoolTemplate.MaxLimit = result.Read <uint>(1); mPoolTemplate[pool_id] = pPoolTemplate; ++count; }while (result.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} objects pools in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); } // Creatures Log.outInfo(LogFilter.ServerLoading, "Loading Creatures Pooling Data..."); { uint oldMSTime = Time.GetMSTime(); // 1 2 3 SQLResult result = DB.World.Query("SELECT guid, pool_entry, chance FROM pool_creature"); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 creatures in pools. DB table `pool_creature` is empty."); } else { uint count = 0; do { ulong guid = result.Read <ulong>(0); uint pool_id = result.Read <uint>(1); float chance = result.Read <float>(2); CreatureData data = Global.ObjectMgr.GetCreatureData(guid); if (data == null) { Log.outError(LogFilter.Sql, "`pool_creature` has a non existing creature spawn (GUID: {0}) defined for pool id ({1}), skipped.", guid, pool_id); continue; } if (!mPoolTemplate.ContainsKey(pool_id)) { Log.outError(LogFilter.Sql, "`pool_creature` pool id ({0}) is out of range compared to max pool id in `pool_template`, skipped.", pool_id); continue; } if (chance < 0 || chance > 100) { Log.outError(LogFilter.Sql, "`pool_creature` has an invalid chance ({0}) for creature guid ({1}) in pool id ({2}), skipped.", chance, guid, pool_id); continue; } PoolTemplateData pPoolTemplate = mPoolTemplate[pool_id]; PoolObject plObject = new PoolObject(guid, chance); if (!mPoolCreatureGroups.ContainsKey(pool_id)) { mPoolCreatureGroups[pool_id] = new PoolGroup <Creature>(); } PoolGroup <Creature> cregroup = mPoolCreatureGroups[pool_id]; cregroup.SetPoolId(pool_id); cregroup.AddEntry(plObject, pPoolTemplate.MaxLimit); mCreatureSearchMap.Add(guid, pool_id); ++count; }while (result.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} creatures in pools in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); } } // Gameobjects Log.outInfo(LogFilter.ServerLoading, "Loading Gameobject Pooling Data..."); { uint oldMSTime = Time.GetMSTime(); // 1 2 3 SQLResult result = DB.World.Query("SELECT guid, pool_entry, chance FROM pool_gameobject"); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 gameobjects in pools. DB table `pool_gameobject` is empty."); } else { uint count = 0; do { ulong guid = result.Read <ulong>(0); uint pool_id = result.Read <uint>(1); float chance = result.Read <float>(2); GameObjectData data = Global.ObjectMgr.GetGOData(guid); if (data == null) { Log.outError(LogFilter.Sql, "`pool_gameobject` has a non existing gameobject spawn (GUID: {0}) defined for pool id ({1}), skipped.", guid, pool_id); continue; } GameObjectTemplate goinfo = Global.ObjectMgr.GetGameObjectTemplate(data.id); if (goinfo.type != GameObjectTypes.Chest && goinfo.type != GameObjectTypes.FishingHole && goinfo.type != GameObjectTypes.GatheringNode && goinfo.type != GameObjectTypes.Goober) { Log.outError(LogFilter.Sql, "`pool_gameobject` has a not lootable gameobject spawn (GUID: {0}, type: {1}) defined for pool id ({2}), skipped.", guid, goinfo.type, pool_id); continue; } if (!mPoolTemplate.ContainsKey(pool_id)) { Log.outError(LogFilter.Sql, "`pool_gameobject` pool id ({0}) is out of range compared to max pool id in `pool_template`, skipped.", pool_id); continue; } if (chance < 0 || chance > 100) { Log.outError(LogFilter.Sql, "`pool_gameobject` has an invalid chance ({0}) for gameobject guid ({1}) in pool id ({2}), skipped.", chance, guid, pool_id); continue; } PoolTemplateData pPoolTemplate = mPoolTemplate[pool_id]; PoolObject plObject = new PoolObject(guid, chance); if (!mPoolGameobjectGroups.ContainsKey(pool_id)) { mPoolGameobjectGroups[pool_id] = new PoolGroup <GameObject>(); } PoolGroup <GameObject> gogroup = mPoolGameobjectGroups[pool_id]; gogroup.SetPoolId(pool_id); gogroup.AddEntry(plObject, pPoolTemplate.MaxLimit); mGameobjectSearchMap.Add(guid, pool_id); ++count; }while (result.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} gameobject in pools in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); } } // Pool of pools Log.outInfo(LogFilter.ServerLoading, "Loading Mother Pooling Data..."); { uint oldMSTime = Time.GetMSTime(); // 1 2 3 SQLResult result = DB.World.Query("SELECT pool_id, mother_pool, chance FROM pool_pool"); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 pools in pools"); } else { uint count = 0; do { uint child_pool_id = result.Read <uint>(0); uint mother_pool_id = result.Read <uint>(1); float chance = result.Read <float>(2); if (!mPoolTemplate.ContainsKey(mother_pool_id)) { Log.outError(LogFilter.Sql, "`pool_pool` mother_pool id ({0}) is out of range compared to max pool id in `pool_template`, skipped.", mother_pool_id); continue; } if (!mPoolTemplate.ContainsKey(child_pool_id)) { Log.outError(LogFilter.Sql, "`pool_pool` included pool_id ({0}) is out of range compared to max pool id in `pool_template`, skipped.", child_pool_id); continue; } if (mother_pool_id == child_pool_id) { Log.outError(LogFilter.Sql, "`pool_pool` pool_id ({0}) includes itself, dead-lock detected, skipped.", child_pool_id); continue; } if (chance < 0 || chance > 100) { Log.outError(LogFilter.Sql, "`pool_pool` has an invalid chance ({0}) for pool id ({1}) in mother pool id ({2}), skipped.", chance, child_pool_id, mother_pool_id); continue; } PoolTemplateData pPoolTemplateMother = mPoolTemplate[mother_pool_id]; PoolObject plObject = new PoolObject(child_pool_id, chance); if (!mPoolPoolGroups.ContainsKey(mother_pool_id)) { mPoolPoolGroups[mother_pool_id] = new PoolGroup <Pool>(); } PoolGroup <Pool> plgroup = mPoolPoolGroups[mother_pool_id]; plgroup.SetPoolId(mother_pool_id); plgroup.AddEntry(plObject, pPoolTemplateMother.MaxLimit); mPoolSearchMap.Add(child_pool_id, mother_pool_id); ++count; }while (result.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} pools in mother pools in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); } } Log.outInfo(LogFilter.ServerLoading, "Loading Quest Pooling Data..."); { uint oldMSTime = Time.GetMSTime(); PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_QUEST_POOLS); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 quests in pools"); } else { List <uint> creBounds; List <uint> goBounds; Dictionary <uint, eQuestTypes> poolTypeMap = new Dictionary <uint, eQuestTypes>(); uint count = 0; do { uint entry = result.Read <uint>(0); uint pool_id = result.Read <uint>(1); if (!poolTypeMap.ContainsKey(pool_id)) { poolTypeMap[pool_id] = 0; } Quest quest = Global.ObjectMgr.GetQuestTemplate(entry); if (quest == null) { Log.outError(LogFilter.Sql, "`pool_quest` has a non existing quest template (Entry: {0}) defined for pool id ({1}), skipped.", entry, pool_id); continue; } if (!mPoolTemplate.ContainsKey(pool_id)) { Log.outError(LogFilter.Sql, "`pool_quest` pool id ({0}) is out of range compared to max pool id in `pool_template`, skipped.", pool_id); continue; } if (!quest.IsDailyOrWeekly()) { Log.outError(LogFilter.Sql, "`pool_quest` has an quest ({0}) which is not daily or weekly in pool id ({1}), use ExclusiveGroup instead, skipped.", entry, pool_id); continue; } if (poolTypeMap[pool_id] == eQuestTypes.None) { poolTypeMap[pool_id] = quest.IsDaily() ? eQuestTypes.Daily : eQuestTypes.Weekly; } eQuestTypes currType = quest.IsDaily() ? eQuestTypes.Daily : eQuestTypes.Weekly; if (poolTypeMap[pool_id] != currType) { Log.outError(LogFilter.Sql, "`pool_quest` quest {0} is {1} but pool ({2}) is specified for {3}, mixing not allowed, skipped.", entry, currType, pool_id, poolTypeMap[pool_id]); continue; } creBounds = mQuestCreatureRelation.LookupByKey(entry); goBounds = mQuestGORelation.LookupByKey(entry); if (creBounds.Empty() && goBounds.Empty()) { Log.outError(LogFilter.Sql, "`pool_quest` lists entry ({0}) as member of pool ({1}) but is not started anywhere, skipped.", entry, pool_id); continue; } PoolTemplateData pPoolTemplate = mPoolTemplate[pool_id]; PoolObject plObject = new PoolObject(entry, 0.0f); if (!mPoolQuestGroups.ContainsKey(pool_id)) { mPoolQuestGroups[pool_id] = new PoolGroup <Quest>(); } PoolGroup <Quest> questgroup = mPoolQuestGroups[pool_id]; questgroup.SetPoolId(pool_id); questgroup.AddEntry(plObject, pPoolTemplate.MaxLimit); mQuestSearchMap.Add(entry, pool_id); ++count; }while (result.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} quests in pools in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); } } // The initialize method will spawn all pools not in an event and not in another pool, this is why there is 2 left joins with 2 null checks Log.outInfo(LogFilter.ServerLoading, "Starting objects pooling system..."); { uint oldMSTime = Time.GetMSTime(); SQLResult result = DB.World.Query("SELECT DISTINCT pool_template.entry, pool_pool.pool_id, pool_pool.mother_pool FROM pool_template" + " LEFT JOIN game_event_pool ON pool_template.entry=game_event_pool.pool_entry" + " LEFT JOIN pool_pool ON pool_template.entry=pool_pool.pool_id WHERE game_event_pool.pool_entry IS NULL"); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Pool handling system initialized, 0 pools spawned."); } else { uint count = 0; do { uint pool_entry = result.Read <uint>(0); uint pool_pool_id = result.Read <uint>(1); if (!CheckPool(pool_entry)) { if (pool_pool_id != 0) { // The pool is a child pool in pool_pool table. Ideally we should remove it from the pool handler to ensure it never gets spawned, // however that could recursively invalidate entire chain of mother pools. It can be done in the future but for now we'll do nothing. Log.outError(LogFilter.Sql, "Pool Id {0} has no equal chance pooled entites defined and explicit chance sum is not 100. This broken pool is a child pool of Id {1} and cannot be safely removed.", pool_entry, result.Read <uint>(2)); } else { Log.outError(LogFilter.Sql, "Pool Id {0} has no equal chance pooled entites defined and explicit chance sum is not 100. The pool will not be spawned.", pool_entry); } continue; } // Don't spawn child pools, they are spawned recursively by their parent pools if (pool_pool_id == 0) { SpawnPool(pool_entry); count++; } }while (result.NextRow()); Log.outDebug(LogFilter.Pool, "Pool handling system initialized, {0} pools spawned in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); } } }
public Target(CreatureData c) : this(c, FightActions.None, 0, FightSecurity.Automatic, FightStances.Stand, Attack.FullAttack, Follow.DoNotFollow) { }
public string GetBestPaladinSpell(CreatureData creatureData, string holySpell, string physicalSpell) { DamageType damageType = creatureData.GetWeakness(new List<DamageType>() { DamageType.Holy, DamageType.Physical }); switch (damageType) { case DamageType.Holy: return holySpell; case DamageType.Physical: return physicalSpell; } return holySpell; }
public string GetBestPaladinSpell(CreatureData creatureData) { return GetBestPaladinSpell(creatureData, "exori san", "exori con"); }
public string GetBestMageSpell(CreatureData creatureData, string deathSpell, string earthSpell, string energySpell, string fireSpell, string iceSpell) { DamageType damageType = creatureData.GetWeakness(new List<DamageType>() { DamageType.Death, DamageType.Earth, DamageType.Energy, DamageType.Fire, DamageType.Ice }); switch (damageType) { case DamageType.Death: return deathSpell; case DamageType.Earth: return earthSpell; case DamageType.Energy: return energySpell; case DamageType.Fire: return fireSpell; case DamageType.Ice: return iceSpell; } return iceSpell; }
/// todo get rid of this many variables passed in function. public void Start(bool isActiveAttacker = true, bool run = false, ObjectGuid playerGUID = default, Quest quest = null, bool instantRespawn = false, bool canLoopPath = false, bool resetWaypoints = true) { // Queue respawn from the point it starts Map map = me.GetMap(); if (map != null) { CreatureData cdata = me.GetCreatureData(); if (cdata != null) { SpawnGroupTemplateData groupdata = cdata.spawnGroupData; if (groupdata != null) { if (WorldConfig.GetBoolValue(WorldCfg.RespawnDynamicEscortNpc) && groupdata.flags.HasAnyFlag(SpawnGroupFlags.EscortQuestNpc) && map.GetCreatureRespawnTime(me.GetSpawnId()) == 0) { me.SetRespawnTime(me.GetRespawnDelay()); me.SaveRespawnTime(); } } } } if (me.GetVictim()) { Log.outError(LogFilter.Scripts, $"EscortAI.Start: (script: {me.GetScriptName()}, creature entry: {me.GetEntry()}) attempts to Start while in combat"); return; } if (HasEscortState(EscortState.Escorting)) { Log.outError(LogFilter.Scripts, $"EscortAI.Start: (script: {me.GetScriptName()}, creature entry: {me.GetEntry()}) attempts to Start while already escorting"); return; } if (!_manualPath && resetWaypoints) { FillPointMovementListForCreature(); } if (_path.nodes.Empty()) { Log.outError(LogFilter.Scripts, $"EscortAI.Start: (script: {me.GetScriptName()}, creature entry: {me.GetEntry()}) starts with 0 waypoints (possible missing entry in script_waypoint. Quest: {(quest != null ? quest.Id : 0)})."); return; } // set variables _activeAttacker = isActiveAttacker; _running = run; _playerGUID = playerGUID; _escortQuest = quest; _instantRespawn = instantRespawn; _returnToStart = canLoopPath; if (_returnToStart && _instantRespawn) { Log.outError(LogFilter.Scripts, $"EscortAI.Start: (script: {me.GetScriptName()}, creature entry: {me.GetEntry()}) is set to return home after waypoint end and instant respawn at waypoint end. Creature will never despawn."); } me.GetMotionMaster().MoveIdle(); me.GetMotionMaster().Clear(MovementSlot.Active); //disable npcflags me.SetNpcFlags(NPCFlags.None); me.SetNpcFlags2(NPCFlags2.None); if (me.HasUnitFlag(UnitFlags.ImmuneToNpc)) { _hasImmuneToNPCFlags = true; me.RemoveUnitFlag(UnitFlags.ImmuneToNpc); } Log.outDebug(LogFilter.Scripts, $"EscortAI.Start: (script: {me.GetScriptName()}, creature entry: {me.GetEntry()}) started with {_path.nodes.Count} waypoints. ActiveAttacker = {_activeAttacker}, Run = {_running}, Player = {_playerGUID}"); // set initial speed me.SetWalk(!_running); _started = false; AddEscortState(EscortState.Escorting); }
public virtual uint GetCreatureEntry(ulong guidlow, CreatureData data) { return(data.id); }
public static FrozenMixin GetNearestFrozenCreature(Vector3 position, float maxRange, BehaviourType creatureType = BehaviourType.Unknown) { if (frozenCreatures.Count < 1) { return(null); } FrozenMixin result = null; float num = maxRange * maxRange; foreach (FrozenMixin frozenMixin in frozenCreatures) { if (frozenMixin.IsFrozenInWater() && (creatureType == BehaviourType.Unknown || CreatureData.GetBehaviourType(frozenMixin.gameObject) == creatureType)) { float sqrMagnitude = (position - frozenMixin.transform.position).sqrMagnitude; if (sqrMagnitude < num) { result = frozenMixin; num = sqrMagnitude; } } } return(result); }
public string GetBestMageSpell(CreatureData creatureData) { return(GetBestMageSpell(creatureData, "exori mort", "exori tera", "exori vis", "exori flam", "exori frigo")); }
static bool HandleListRespawnsCommand(StringArguments args, CommandHandler handler) { Player player = handler.GetSession().GetPlayer(); Map map = player.GetMap(); uint range = 0; if (!args.Empty()) { range = args.NextUInt32(); } List <RespawnInfo> respawns = new List <RespawnInfo>(); Locale locale = handler.GetSession().GetSessionDbcLocale(); string stringOverdue = Global.ObjectMgr.GetCypherString(CypherStrings.ListRespawnsOverdue, locale); string stringCreature = Global.ObjectMgr.GetCypherString(CypherStrings.ListRespawnsCreatures, locale); string stringGameobject = Global.ObjectMgr.GetCypherString(CypherStrings.ListRespawnsGameobjects, locale); uint zoneId = player.GetZoneId(); if (range != 0) { handler.SendSysMessage(CypherStrings.ListRespawnsRange, stringCreature, range); } else { handler.SendSysMessage(CypherStrings.ListRespawnsZone, stringCreature, GetZoneName(zoneId, handler.GetSessionDbcLocale()), zoneId); } handler.SendSysMessage(CypherStrings.ListRespawnsListheader); map.GetRespawnInfo(respawns, SpawnObjectTypeMask.Creature, range != 0 ? 0 : zoneId); foreach (RespawnInfo ri in respawns) { CreatureData data = Global.ObjectMgr.GetCreatureData(ri.spawnId); if (data == null) { continue; } if (range != 0 && !player.IsInDist(data.spawnPoint, range)) { continue; } uint gridY = ri.gridId / MapConst.MaxGrids; uint gridX = ri.gridId % MapConst.MaxGrids; string respawnTime = ri.respawnTime > Time.UnixTime ? Time.secsToTimeString((ulong)(ri.respawnTime - Time.UnixTime), true) : stringOverdue; handler.SendSysMessage($"{ri.spawnId} | {ri.entry} | [{gridX},{gridY}] | {GetZoneName(ri.zoneId, handler.GetSessionDbcLocale())} ({ri.zoneId}) | {(map.IsSpawnGroupActive(data.spawnGroupData.groupId) ? respawnTime : "inactive")}"); } respawns.Clear(); if (range != 0) { handler.SendSysMessage(CypherStrings.ListRespawnsRange, stringGameobject, range); } else { handler.SendSysMessage(CypherStrings.ListRespawnsZone, stringGameobject, GetZoneName(zoneId, handler.GetSessionDbcLocale()), zoneId); } handler.SendSysMessage(CypherStrings.ListRespawnsListheader); map.GetRespawnInfo(respawns, SpawnObjectTypeMask.GameObject, range != 0 ? 0 : zoneId); foreach (RespawnInfo ri in respawns) { GameObjectData data = Global.ObjectMgr.GetGameObjectData(ri.spawnId); if (data == null) { continue; } if (range != 0 && !player.IsInDist(data.spawnPoint, range)) { continue; } uint gridY = ri.gridId / MapConst.MaxGrids; uint gridX = ri.gridId % MapConst.MaxGrids; string respawnTime = ri.respawnTime > Time.UnixTime ? Time.secsToTimeString((ulong)(ri.respawnTime - Time.UnixTime), true) : stringOverdue; handler.SendSysMessage($"{ri.spawnId} | {ri.entry} | [{gridX},{gridY}] | {GetZoneName(ri.zoneId, handler.GetSessionDbcLocale())} ({ri.zoneId}) | {(map.IsSpawnGroupActive(data.spawnGroupData.groupId) ? respawnTime : "inactive")}"); } return(true); }
public void AddTarget(string name, FightActions action, byte priority, FightSecurity security, FightStances stance, Attack attackMode, Follow followMode) { CreatureData c = null; if (CreatureLists.AllCreatures.ContainsKey(name)) { c = CreatureLists.AllCreatures[name]; } else { c = new CreatureData(name, 0, 0, 0, 0, 0, false, false, FrontAttack.None, null, null, null, null, null); } Targets.Add(new Target(c, action, priority, security, stance, attackMode, followMode)); }
void Spawn1Object(PoolObject obj) { switch (typeof(T).Name) { case "Creature": CreatureData data = Global.ObjectMgr.GetCreatureData(obj.guid); if (data != null) { Global.ObjectMgr.AddCreatureToGrid(obj.guid, data); // Spawn if necessary (loaded grids only) Map map = Global.MapMgr.CreateBaseMap(data.mapid); // We use spawn coords to spawn if (!map.Instanceable() && map.IsGridLoaded(data.posX, data.posY)) { Creature creature = new Creature(); if (!creature.LoadCreatureFromDB(obj.guid, map)) { return; } } } break; case "GameObject": GameObjectData data_ = Global.ObjectMgr.GetGOData(obj.guid); if (data_ != null) { Global.ObjectMgr.AddGameObjectToGrid(obj.guid, data_); // Spawn if necessary (loaded grids only) // this base map checked as non-instanced and then only existed Map map = Global.MapMgr.CreateBaseMap(data_.mapid); // We use current coords to unspawn, not spawn coords since creature can have changed grid if (!map.Instanceable() && map.IsGridLoaded(data_.posX, data_.posY)) { GameObject pGameobject = new GameObject(); if (!pGameobject.LoadGameObjectFromDB(obj.guid, map, false)) { return; } else { if (pGameobject.isSpawnedByDefault()) { map.AddToMap(pGameobject); } } } } break; case "Pool": Global.PoolMgr.SpawnPool((uint)obj.guid); break; case "Quest": // Creatures var questMap = Global.ObjectMgr.GetCreatureQuestRelationMap(); var qr = Global.PoolMgr.mQuestCreatureRelation.LookupByKey(obj.guid); foreach (var creature in qr) { Log.outDebug(LogFilter.Pool, "PoolGroup<Quest>: Adding quest {0} to creature {1}", obj.guid, creature); questMap.Add(creature, (uint)obj.guid); } // Gameobjects questMap = Global.ObjectMgr.GetGOQuestRelationMap(); qr = Global.PoolMgr.mQuestGORelation.LookupByKey(obj.guid); foreach (var go in qr) { Log.outDebug(LogFilter.Pool, "PoolGroup<Quest>: Adding quest {0} to GO {1}", obj.guid, go); questMap.Add(go, (uint)obj.guid); } break; } }
/// <inheritdoc /> public void AddOrUpdateDirty(CreatureData data) { DirtyCreatures.Remove(data.GlobalID); DirtyCreatures.Add(data.GlobalID, data, ActionType.AddOrChanged); }