public override void Execte(T enemyEntity) { MonitorComponent monitorComp = (MonitorComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Monitor); PropertyComponent propertyComp = (PropertyComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Property); DeadComponent deadComp = (DeadComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Dead); //如果没有敌人 if (monitorComp.m_enemy.Count == 0) { enemyEntity.ChangeDecision(AIComponent.Decision.Patrol); return; } else { ////如果遇到了敌人,且敌人的距离足够近 //double threat = FuzzyLogic.DistanceThreat (CalculateDistance (enemyEntity.m_entity), propertyComp.HP); //if (threat > 0.4f) { enemyEntity.ChangeDecision(AIComponent.Decision.Attack); return; // return; //} else { // enemyEntity.ChangeDecision (AIComponent.Decision.Escape); // return; //} } //计算受伤 enemyEntity.m_events.AddInjure(tmpHp - deadComp.hp); tmpHp = deadComp.hp; CallSupport(enemyEntity); return; }
public override void Execte(T enemyEntity) { Debug.Log("exec survey!"); MonitorComponent monitorComp = (MonitorComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Monitor); PropertyComponent propertyComp = (PropertyComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Property); DeadComponent deadComp = (DeadComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Dead); //发现敌人 if (monitorComp.m_enemy.Count != 0) { //倾向攻击攻击 if (deadComp.hp / propertyComp.HP > 0.2f) { enemyEntity.ChangeDecision(AIComponent.Decision.Attack); return; } else { //如果有同伴在旁边,那么就进行攻击 if (AiToInput.ExistEnemy()) { enemyEntity.ChangeDecision(AIComponent.Decision.CallSupport); return; } } } //如果还是听到声音 if (monitorComp.m_voice.Count == 0) { //if (deadComp.hp / propertyComp.HP > 0.2f) { //float j = Random.value; //float surveyDemage = enemyEntity.m_events.DecisionExpectDemage (AIComponent.Decision.Survey); //float patrolDemage = enemyEntity.m_events.DecisionExpectDemage (AIComponent.Decision.Patrol); //Debug.Log ("surveyDemage" + surveyDemage + "patrolDemage" + patrolDemage); //if (j > surveyDemage / (surveyDemage + patrolDemage)) { //如果听到声音,生命充足,且根据历史,直接前去调查可以造成更多的伤害 enemyEntity.ChangeDecision(AIComponent.Decision.Patrol); // return; // } //} else { // float j = Random.value; // float surveyInjure = enemyEntity.m_events.DecisionExpectInjure (AIComponent.Decision.Survey); // float patrolInjeure = enemyEntity.m_events.DecisionExpectInjure (AIComponent.Decision.Patrol); // if (j > patrolInjeure / (surveyInjure + patrolInjeure)) { // //听到声音。生命不足,但是前去调查可以保存更多的生命 // enemyEntity.ChangeDecision (AIComponent.Decision.Patrol); // return; // } //} } Debug.Log("run survey!"); //计算受伤 enemyEntity.m_events.AddInjure(tmpHp - deadComp.hp); tmpHp = deadComp.hp; Survey(enemyEntity.m_entity); return; }
public static void SSetTargetCargoBytes_Prefix(MonitorComponent __instance, int __0) { if (Multiplayer.IsActive && !Multiplayer.Session.Warning.IsIncomingMonitorPacket) { int planetId = GameMain.data.localPlanet == null ? -1 : GameMain.data.localPlanet.id; Multiplayer.Session.Network.SendPacketToLocalStar( new MonitorSettingUpdatePacket(planetId, __instance.id, MonitorSettingEvent.SetTargetCargoBytes, __0)); } }
public static void SetLength_Prefix(MonitorComponent __instance, bool __0) { if (Multiplayer.IsActive && !Multiplayer.Session.Warning.IsIncomingMonitorPacket) { int planetId = GameMain.data.localPlanet == null ? -1 : GameMain.data.localPlanet.id; Multiplayer.Session.Network.SendPacketToLocalStar( new SpeakerSettingUpdatePacket(planetId, __instance.id, SpeakerSettingEvent.SetRepeat, __0 ? 1 : 0)); } }
public static void SetPassColorId_Prefix(MonitorComponent __instance, byte __0) { if (Multiplayer.IsActive && !Multiplayer.Session.Warning.IsIncomingMonitorPacket) { //Assume the monitor is on local planet int planetId = GameMain.data.localPlanet == null ? -1 : GameMain.data.localPlanet.id; Multiplayer.Session.Network.SendPacketToLocalStar( new MonitorSettingUpdatePacket(planetId, __instance.id, MonitorSettingEvent.SetPassColorId, __0)); } }
public static void SetTargetBelt_Prefix(MonitorComponent __instance, int __0, int __1) { //This is required for putting monitor over belt works properly if (Multiplayer.IsActive && !Multiplayer.Session.Warning.IsIncomingMonitorPacket) { int planetId = GameMain.data.localPlanet == null ? -1 : GameMain.data.localPlanet.id; Multiplayer.Session.Network.SendPacketToLocalStar( new MonitorSettingUpdatePacket(planetId, __instance.id, MonitorSettingEvent.SetTargetBelt, __0, __1)); } }
public static void SetLength_Prefix(MonitorComponent __instance, float __0) { if (Multiplayer.IsActive && !Multiplayer.Session.Warning.IsIncomingMonitorPacket) { int planetId = GameMain.data.localPlanet == null ? -1 : GameMain.data.localPlanet.id; int p1 = BitConverter.ToInt32(BitConverter.GetBytes(__0), 0); Multiplayer.Session.Network.SendPacketToLocalStar( new SpeakerSettingUpdatePacket(planetId, __instance.id, SpeakerSettingEvent.SetLength, p1)); } }
static public bool FriendInSight(BasicEntity entity) { MonitorComponent monitor = entity.GetComponent <MonitorComponent> (); foreach (BasicEntity e in StateStaticComponent.enemyActionList) { if (monitor.m_view.Contains(e.GetComponent <BlockInfoComponent> ().m_logicPosition)) { return(true); } } return(false); }
public static bool InternalUpdate_Prefix(MonitorComponent __instance, CargoTraffic _traffic, EntityData[] _entityPool, SpeakerComponent[] _speakerPool, AnimData[] _animPool) { if (Multiplayer.IsActive && __instance.targetBeltId > _traffic.beltPool.Length) { if (Multiplayer.Session.LocalPlayer.IsHost) { _traffic.factory.RemoveEntityWithComponents(__instance.entityId); WarningManager.DisplayTemporaryWarning($"Broken Traffic Monitor detected on {_traffic.factory.planet.displayName}\nIt was removed, clients should reconnect!", 15000); } return(false); } return(true); }
public override void Enter(T enemyEntity) { enemyEntity.m_entity.GetComponent <AIComponent> ().m_currentDecision = AIComponent.Decision.Attack; Debug.Log("enter attack!"); MonitorComponent monitorComp = (MonitorComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Monitor); target = monitorComp.m_enemy [0]; DeadComponent selfDeadComp = (DeadComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Dead); DeadComponent targetDeadComp = (DeadComponent)target.GetSpecicalComponent(ComponentType.Dead); tmpHp = selfDeadComp.hp; tmpTargetHp = targetDeadComp.hp; //enemyEntity.m_events.AddEvent (AIComponent.Decision.Attack); Attack(enemyEntity.m_entity); return; }
public int CalculateDistance(BasicEntity entity) { MonitorComponent monitorComp = (MonitorComponent)entity.GetSpecicalComponent(ComponentType.Monitor); BasicEntity player = monitorComp.m_enemy [0]; player.GetComponent <BlockInfoComponent> ().m_blockType = BlockType.None; List <Vector3> pathLsit = FindPath.GetPath(entity.GetComponent <BlockInfoComponent> ().m_logicPosition, player.GetComponent <BlockInfoComponent> ().m_logicPosition); if (pathLsit != null) { Debug.Log("cant find path!!!!!!!!!!!"); return(0); } else { return(pathLsit.Count); } }
public override void Execte(T enemyEntity) { Debug.Log("check patrol!"); MonitorComponent monitorComp = (MonitorComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Monitor); PropertyComponent propertyComp = (PropertyComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Property); DeadComponent deadComp = (DeadComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Dead); if (monitorComp.m_enemy.Count != 0) { //if (deadComp.hp / propertyComp.HP > 0.2f) { //发现敌人,且生命值充足 enemyEntity.ChangeDecision(AIComponent.Decision.Attack); return; //} else { // if (AiToInput.ExistEnemy () == true) { // enemyEntity.ChangeDecision (AIComponent.Decision.CallSupport); // return; // } //} } if (monitorComp.m_voice.Count != 0) { //if (deadComp.hp / propertyComp.HP > 0.2f) { enemyEntity.ChangeDecision(AIComponent.Decision.Survey); return; //} } Debug.Log("run patrol!"); //计算在上一回合中受到的伤害 enemyEntity.m_events.AddInjure(m_tmpHp - deadComp.hp); m_tmpHp = deadComp.hp; Patrol(enemyEntity.m_entity); return; }
static public bool CallFriend(BasicEntity entity, List <BasicEntity> player) { if (player.Count == 0 || entity == null) { return(false); } MonitorComponent monitor = entity.GetComponent <MonitorComponent> (); List <Vector3> view = monitor.m_view; VoxelBlocks map = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks> (); bool isFind = false; foreach (Vector3 pos in view) { BasicEntity e = map.GetBlockByLogicPos(pos).entity; if (e != null && e.GetComponent <BlockInfoComponent> ().m_blockType == BlockType.Enemy) { isFind = true; e.GetComponent <MonitorComponent> ().m_enemy.AddRange(player); } } return(isFind); }
private void buttonTest1_Click(object sender, EventArgs e) { var monitor = new MonitorComponent(_store); monitor.Run(); }
//添加某一类型的组件 public BasicComponent AddComponent(ComponentType type) { if (ExistSpecialComponent(type)) { //Debug.Log("Exist same component Type" + type); return(GetSpecicalComponent(type)); } //Debug.Log ("Add component" + type + " in " + gameObject); PropertyComponent property = GetComponent <PropertyComponent> (); switch (type) { case ComponentType.Property: PropertyComponent propertyComp = gameObject.AddComponent <PropertyComponent> (); propertyComp.Init(ComponentType.Property, this); m_components.Add(propertyComp); return(propertyComp); case ComponentType.Dead: DeadComponent deadComp = gameObject.AddComponent <DeadComponent> (); deadComp.Init(ComponentType.Dead, this); deadComp.hp = property.HP; m_components.Add(deadComp); return(deadComp); case ComponentType.State: StateComponent stateComp = gameObject.AddComponent <StateComponent> (); stateComp.Init(ComponentType.State, this); m_components.Add(stateComp); stateComp.m_actionPoint = property.AP; return(stateComp); case ComponentType.Ability: AbilityComponent abilityComp = gameObject.AddComponent <AbilityComponent> (); abilityComp.Init(ComponentType.Ability, this); m_components.Add(abilityComp); return(abilityComp); case ComponentType.Hide: HideComponent hideComp = gameObject.AddComponent <HideComponent> (); hideComp.Init(ComponentType.Hide, this); m_components.Add(hideComp); return(hideComp); case ComponentType.Move: MoveComponent moveComp = gameObject.AddComponent <MoveComponent> (); moveComp.Init(ComponentType.Move, this); m_components.Add(moveComp); moveComp.moveSpeed = property.moveSpd; moveComp.SPD = property.SPD; return(moveComp); case ComponentType.Attack: AttackComponent attackComp = gameObject.AddComponent <AttackComponent> (); attackComp.Init(ComponentType.Attack, this); m_components.Add(attackComp); attackComp.STR = property.STR; return(attackComp); case ComponentType.Input: InputComponent inputComp = gameObject.AddComponent <InputComponent> (); inputComp.Init(ComponentType.Input, this); m_components.Add(inputComp); return(inputComp); case ComponentType.CheerUp: CheerUpComponent cheerUpComp = gameObject.AddComponent <CheerUpComponent> (); cheerUpComp.Init(ComponentType.CheerUp, this); m_components.Add(cheerUpComp); return(cheerUpComp); case ComponentType.Monitor: MonitorComponent monitorComp = gameObject.AddComponent <MonitorComponent> (); monitorComp.Init(ComponentType.Monitor, this); m_components.Add(monitorComp); monitorComp.m_SightArea = property.HRZ; return(monitorComp); case ComponentType.Knock: KnockComponent knockComp = gameObject.AddComponent <KnockComponent> (); knockComp.Init(ComponentType.Knock, this); m_components.Add(knockComp); knockComp.m_ridus = property.HRZ; return(knockComp); case ComponentType.Item: ItemComponent itemComp = gameObject.AddComponent <ItemComponent> (); itemComp.Init(ComponentType.Item, this); itemComp.item = property.item; itemComp.numLimit = property.itemLimit; m_components.Add(itemComp); return(itemComp); case ComponentType.AI: AIComponent aiComp = gameObject.AddComponent <AIComponent> (); aiComp.Init(ComponentType.AI, this); m_components.Add(aiComp); return(aiComp); case ComponentType.UI: UIComponent uiComp = gameObject.AddComponent <UIComponent>(); uiComp.Init(ComponentType.UI, this); m_components.Add(uiComp); return(uiComp); default: return(null); } }
public IViewConfigurable View(MonitorComponent component) { return(new MonitorForm(component)); }
public MonitorForm(MonitorComponent com) { InitializeComponent(); _com = com; }
public override void Execte(T enemyEntity) { Debug.Log("exec attack!"); MonitorComponent monitorComp = (MonitorComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Monitor); PropertyComponent propertyComp = (PropertyComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Property); DeadComponent deadComp = (DeadComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Dead); //生命值不足,且上一个动作不是呼叫朋友 if (deadComp.hp < 0.1f * propertyComp.HP && enemyEntity.m_events.CurrentDecision() != AIComponent.Decision.CallSupport) { //同时有朋友存在 if (AiToInput.ExistEnemy()) { enemyEntity.ChangeDecision(AIComponent.Decision.CallSupport); return; } } //如果敌人已经死亡 if (target == null || target.m_components.Count == 0) { //如果附近还有敌人 if (monitorComp.m_enemy.Count != 0) { target = monitorComp.m_enemy [0]; } if (monitorComp.m_enemy.Count != 0) { if (deadComp.hp / propertyComp.HP > 0.3f) { // 如果有玩家,且敌人的生命值较高的话,切换对象攻击,切换对象会在enter时进行 enemyEntity.ChangeDecision(AIComponent.Decision.Attack); return; } else { //有玩家,但是生命值不高,可以逃跑 if (AiToInput.ExistEnemy() && enemyEntity.m_events.CurrentDecision() != AIComponent.Decision.CallSupport) { enemyEntity.ChangeDecision(AIComponent.Decision.CallSupport); return; } } } if (monitorComp.m_voice.Count != 0) { //float i = Random.value; //double degreeAttack = FuzzyLogic.AttackBelong (deadComp.hp, propertyComp.HP); //double degreeProtect = FuzzyLogic.ProtectBelong (deadComp.hp, propertyComp.HP); if (deadComp.hp / propertyComp.HP > 0.2f) { //听到声音,生命充足 //float j = Random.value; //float surveyDemage = enemyEntity.m_events.DecisionExpectDemage (AIComponent.Decision.Survey); //float patrolDemage = enemyEntity.m_events.DecisionExpectDemage (AIComponent.Decision.Patrol); //Debug.Log ("surveyDemage" + surveyDemage + "patrolDemage" + patrolDemage); //根据历史计算哪种行动造成的伤害更多 //if (j >0.3f) { enemyEntity.ChangeDecision(AIComponent.Decision.Survey); return; //} else { //enemyEntity.ChangeDecision (AIComponent.Decision.Patrol); //return; //} } else { //float j = Random.value; //float surveyInjure = enemyEntity.m_events.DecisionExpectInjure (AIComponent.Decision.Survey); //float patrolInjeure = enemyEntity.m_events.DecisionExpectInjure (AIComponent.Decision.Patrol); //if (j > 0.3f) { if (AiToInput.ExistEnemy() && enemyEntity.m_events.CurrentDecision() != AIComponent.Decision.CallSupport) { enemyEntity.ChangeDecision(AIComponent.Decision.CallSupport); return; } //} else { //enemyEntity.ChangeDecision (AIComponent.Decision.Patrol); //return; //} } } //敌人死亡且旁边没有敌人,返回巡逻 enemyEntity.ChangeDecision(AIComponent.Decision.Patrol); return; } Debug.Log("run attack!"); //计算受伤 DeadComponent targetDeadComp = (DeadComponent)target.GetSpecicalComponent(ComponentType.Dead); enemyEntity.m_events.AddInjure(tmpHp - deadComp.hp); enemyEntity.m_events.AddDemage(tmpTargetHp - targetDeadComp.hp); tmpHp = deadComp.hp; tmpTargetHp = targetDeadComp.hp; Attack(enemyEntity.m_entity); return; }
public override void Execute(List <BasicEntity> entities) { foreach (var e in entities) { MonitorComponent monitor = e.GetComponent <MonitorComponent>(); if (monitor == null) { return; } //若监视范围为空或者实体进行移动,重置监控范围 List <BasicEntity> oldEnemy = monitor.m_enemy; monitor.m_enemy = new List <BasicEntity>(); UISimple ui = GameObject.Find("UI").GetComponent <UISimple>(); VoxelBlocks map = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks>(); if (monitor.m_view == null || monitor.m_view.Contains(e.GetComponent <BlockInfoComponent>().m_logicPosition)) { List <Vector3> list = FindPath.GetArea(e.GetComponent <BlockInfoComponent>().m_logicPosition, monitor.m_SightArea); //获取自身位置 Vector3 s = e.GetComponent <BlockInfoComponent>().m_logicPosition; //初始化视野列表 monitor.m_view = new List <Vector3>(); //获取所有能看到的点 foreach (var pos in list) { if (InView(pos, s)) { //添加视野点并判断是否为玩家 monitor.m_view.Add(pos); BasicEntity entity = map.GetBlockByLogicPos(pos).entity; //判断是否为玩家 if (entity != null) { if (entity.GetComponent <BlockInfoComponent>().m_blockType == BlockType.Player && !monitor.m_enemy.Contains(entity)) { //添加到敌人列表里 monitor.m_enemy.Add(entity); } } } } //判断视野里是否出现新的敌人 foreach (BasicEntity enemy in monitor.m_enemy) { if (!oldEnemy.Contains(enemy)) { monitor.GetComponent <StateComponent>().FindEnemy(); break; } } //ui.ShowWornArea(e); } else { //查找所有在视野里的玩家 foreach (var pos in monitor.m_view) { BasicEntity entity = map.GetBlockByLogicPos(pos).entity; //判断是否为玩家 if (entity != null) { if (entity.GetComponent <BlockInfoComponent>().m_blockType == BlockType.Player && !monitor.m_enemy.Contains(entity)) { //添加到敌人列表里 monitor.m_enemy.Add(entity); } } } } foreach (var enemy in oldEnemy) { if (monitor.m_enemy.Contains(enemy)) { continue; } monitor.m_voice.Add(enemy.GetComponent <BlockInfoComponent>().m_logicPosition); } } }