public override void Execute(List <BasicEntity> entities) { for (int i = 0; i < entities.Count; i++) { BasicEntity e = entities [i]; DeadComponent dead = e.GetComponent <DeadComponent> (); PropertyComponent propertyComp = (PropertyComponent)e.GetSpecicalComponent(ComponentType.Property); if (dead.hp <= 0) { if (propertyComp.m_characterType == PropertyComponent.CharacterType.Heretic || propertyComp.m_characterType == PropertyComponent.CharacterType.Deepone) { AIComponent aiComp = (AIComponent)e.GetSpecicalComponent(ComponentType.AI); //todo //aiComp.m_enemy.Dead (); } //播放死亡动画 RemoveDead(dead); dead.m_entity.RemoveAllComponent(); continue; } if (dead.san == 0) { } } }
public void Object_Property_Find() { var properties = typeof(Person).GetProperties(BindingFlags.Public | BindingFlags.Instance); var person = new Person(); var _prop = new PropertyComponent(); var expecting = properties.First(a => a.Name == "FirstName"); var result = _.Object.Property.Find(person, "FirstName"); Assert.AreEqual(expecting, result); result = _.Object.Property.Find(person, "firstname", false); Assert.AreEqual(expecting, result); result = _.Object.Property.Find(person, "DoesNotHave"); Assert.IsNull(result); result = _prop.Find(person, "firstname", true); Assert.IsNull(result); result = _prop.Find(person, "firstname"); Assert.IsNull(result); }
public void InitAbility(BasicEntity entity) { PropertyComponent propertyComponent = (PropertyComponent)entity.GetSpecicalComponent(ComponentType.Property); if (propertyComponent.m_characterType == PropertyComponent.CharacterType.Null) { return; } switch (propertyComponent.m_characterType) { case PropertyComponent.CharacterType.Veteran: AddVeteranAbility(entity); break; case PropertyComponent.CharacterType.Hacker: AddHackerAbility(entity); break; case PropertyComponent.CharacterType.Drone: AddDroneAbility(entity); break; case PropertyComponent.CharacterType.Heretic: AddHereticAbility(entity); break; case PropertyComponent.CharacterType.Deepone: AddDeeponeAbility(entity); break; } }
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; }
private static IConstructorComponent CreateTestTarget() { var cacher = new CacheComponent(new Underscore.Function.CompactComponent(), new Underscore.Utility.CompactComponent()); var props = new PropertyComponent(); return(new ConstructorComponent(cacher, props)); }
private void TryParseSyntaxTree() { SyntaxTree syntaxTree; if (this.Document.TryGetSyntaxTree(out syntaxTree)) { IEnumerable<SyntaxNode> nodes = syntaxTree.GetRoot().DescendantNodes(); foreach (SyntaxNode node in nodes) { if (node is MemberDeclarationSyntax) { PropertyDeclarationSyntax property = node as PropertyDeclarationSyntax; if (property != null) { PropertyComponent propertyComponent = new PropertyComponent(); propertyComponent.Name = property.Identifier.ToString(); propertyComponent.LineNumber = this.GetStartLinePosition(property.SyntaxTree, property.Span); this.Compoents.Add(propertyComponent); } MethodDeclarationSyntax method = node as MethodDeclarationSyntax; if (method != null) { MethodComponent methodComponent = new MethodComponent(); methodComponent.Name = method.Identifier.ToString(); methodComponent.LineNumber = this.GetStartLinePosition(method.SyntaxTree, method.Span); this.Compoents.Add(methodComponent); } } } } }
public void Object_Property_Find() { var properties = typeof(Person).GetProperties(BindingFlags.Public | BindingFlags.Instance); var person = new Person(); var _prop = new PropertyComponent(); var expecting = properties.First(a => a.Name == "FirstName"); var result = _.Object.Property.Find(person, "FirstName"); Assert.AreEqual(expecting, result); result = _.Object.Property.Find(person, "firstname", false); Assert.AreEqual(expecting, result); result = _.Object.Property.Find(person, "DoesNotHave"); Assert.IsNull(result); result = _prop.Find(person, "firstname", true); Assert.IsNull(result); result = _prop.Find(person, "firstname"); Assert.IsNull(result); }
public override void Init(List <BasicEntity> entities) { base.Init(entities); playerActionList = new List <BasicEntity> (); enemyActionList = new List <BasicEntity> (); foreach (BasicEntity e in entities) { AbilityManager abilityManager = new AbilityManager(); //注册长期性的组件 abilityManager.InitCommomAbility(e); BlockType type = e.GetComponent <BlockInfoComponent> ().m_blockType; switch (type) { case BlockType.Enemy: abilityManager.InitEnemyCommomAbility(e); break; case BlockType.Player: abilityManager.InitPlayerCommomAbility(e); break; default: Debug.Log("please set currect blockType type in " + e.gameObject.name); break; } //添加长期组件 abilityManager.AddResidentComponent(e); PropertyComponent property = (PropertyComponent)e.GetSpecicalComponent(ComponentType.Property); //向能力列表中增加不同的能力组件 switch (property.m_characterType) { case PropertyComponent.CharacterType.Veteran: abilityManager.AddVeteranAbility(e); break; case PropertyComponent.CharacterType.Hacker: abilityManager.AddHackerAbility(e); break; case PropertyComponent.CharacterType.Drone: abilityManager.AddDroneAbility(e); break; case PropertyComponent.CharacterType.Heretic: abilityManager.AddHereticAbility(e); break; case PropertyComponent.CharacterType.Deepone: abilityManager.AddDeeponeAbility(e); break; default: Debug.Log("please set currect character type in " + e.gameObject.name); break; } } }
public void Init() { if (!PropertyComponent) { m_PropertyInfos = new PropertyInfo[0]; m_PropertyNameList = new string[0]; return; } m_PropertyInfos = PropertyComponent.GetType().GetProperties(); Array.Sort(m_PropertyInfos, (e1, e2) => string.Compare(e1.Name, e2.Name, StringComparison.Ordinal)); m_PropertyNameList = m_PropertyInfos.Select(e => e.Name).ToArray(); }
public static PropertyComponent?GetComponentsFromLine(string line) { if (PropertyHelpers.IsRowVersion(line)) { return(null); } if (PropertyHelpers.IsNameSpace(line)) { return(null); } PropertyComponent propertyComponent = new PropertyComponent { IsArray = PropertyHelpers.IsArray(line) }; string[] components = line.Trim().Split(" "); foreach (string component in components) { if (PropertyHelpers.IsAccessModifiers(component) || PropertyHelpers.IsGetOrSet(component)) { continue; } if (PropertyHelpers.IsPropertyType(component)) { propertyComponent.PropertyType = PropertyHelpers.GetPropertyTypeFromComponent(component); propertyComponent.PropertyTypeString = component; } else if (PropertyHelpers.IsVirtual(component)) { propertyComponent.PropertyType = PropertyType.PartOutput; } else { if (PropertyHelpers.IsArray(component)) { propertyComponent.ArrayType = PropertyHelpers.GetArrayTypeFromLine(component); } propertyComponent.Name = component; if (string.IsNullOrEmpty(propertyComponent.PropertyTypeString)) { propertyComponent.PropertyTypeString = component; } } } return(propertyComponent); }
public void LoadInfo() { if (currentRole == null) { return; } PropertyComponent c_Pro = currentRole.GetComponent <PropertyComponent>(); DeadComponent c_Dead = currentRole.GetComponent <DeadComponent>(); StateComponent c_State = currentRole.GetComponent <StateComponent>(); transform.Find("HP").GetComponent <Text>().text = "HP: " + c_Dead.hp.ToString() + "/" + c_Pro.HP.ToString(); transform.Find("AP").GetComponent <Text>().text = "AP: " + c_State.m_actionPoint.ToString() + "/" + c_Pro.AP.ToString(); transform.Find("Name").GetComponent <Text>().text = "Name: " + c_Pro.name; transform.Find("ATK").GetComponent <Text>().text = "ATK: " + c_Pro.STR.ToString(); transform.Find("SPD").GetComponent <Text>().text = "SPD: " + c_Pro.SPD.ToString(); }
private void InitPlayerActionList(List <BasicEntity> entities) { playerActionList.Clear(); //获取实体 foreach (BasicEntity e in entities) { DeadComponent deadComp = (DeadComponent)e.GetSpecicalComponent(ComponentType.Dead); StateComponent stateComponent = (StateComponent)e.GetSpecicalComponent(ComponentType.State); if (deadComp != null && deadComp.hp <= 0) { continue; } PropertyComponent PropertyComponent = (PropertyComponent)e.GetSpecicalComponent(ComponentType.Property); if (PropertyComponent.m_characterType == PropertyComponent.CharacterType.Veteran || PropertyComponent.m_characterType == PropertyComponent.CharacterType.Hacker || PropertyComponent.m_characterType == PropertyComponent.CharacterType.Drone) { //将实体入列 playerActionList.Add(e); } } if (playerActionList.Count == 0) { Skyunion.UIManager.Instance().ShowPanel <UIGameFailPanel>(); } //TODO:后续修改 playerActionList.Sort(delegate(BasicEntity x, BasicEntity y) { PropertyComponent stateX = (PropertyComponent)x.GetSpecicalComponent(ComponentType.Property); PropertyComponent stateY = (PropertyComponent)y.GetSpecicalComponent(ComponentType.Property); Debug.Log("stateX.m_agility : " + stateX.m_agility + "stateY.m_agility" + stateY.m_agility); return(-stateX.m_agility.CompareTo(stateY.m_agility)); }); foreach (BasicEntity e in playerActionList) { Debug.Log(e.gameObject.name + "->"); } StateStaticComponent.playerActionList = playerActionList; //确定现在在行动的角色1.是否又有角色在行动。2,角色的行动点是否已经耗尽 }
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; }
private void updateInfo() { if (current == null) { return; } PropertyComponent c_Pro = currentRole.GetComponent <PropertyComponent>(); DeadComponent c_Dead = currentRole.GetComponent <DeadComponent>(); StateComponent c_State = currentRole.GetComponent <StateComponent>(); if (c_Pro == null || c_Dead == null || c_State == null) { return; } current.Find("HP").GetComponent <Text>().text = "HP:" + c_Dead.hp.ToString(); current.Find("AP").GetComponent <Text>().text = "AP:" + c_State.m_actionPoint.ToString(); current.Find("Name").GetComponent <Text>().text = c_Pro.name; current.Find("HPSlider").GetComponent <Slider>().maxValue = c_Pro.HP; current.Find("HPSlider").GetComponent <Slider>().value = c_Dead.hp; current.Find("APSlider").GetComponent <Slider>().maxValue = c_Pro.AP; current.Find("APSlider").GetComponent <Slider>().value = c_State.m_actionPoint; foreach (BasicEntity role in StateStaticComponent.playerActionList) { if (role == currentRole) { continue; } PropertyComponent f_Pro = role.GetComponent <PropertyComponent>(); DeadComponent f_Dead = role.GetComponent <DeadComponent>(); if (f_Pro == null || f_Dead == null) { continue; } others.Find("HP").GetComponent <Text>().text = "HP:" + f_Dead.hp.ToString(); others.Find("Name").GetComponent <Text>().text = f_Pro.name; others.Find("HPSlider").GetComponent <Slider>().maxValue = f_Pro.HP; others.Find("HPSlider").GetComponent <Slider>().value = f_Dead.hp; } }
public void FunctionalCtorTestParameterless() { var cacheComponent = new CacheComponent(new Underscore.Function.CompactComponent(), new Underscore.Utility.CompactComponent()); var propComponent = new PropertyComponent(); var ctorComponent = new ConstructorComponent(cacheComponent, propComponent); //get the ctor for string builder //empty ctor var strBuilder = new StringBuilder(); var strBuilder = new StringBuilder(); const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; var expecting = from i in typeof(StringBuilder).GetConstructors(flags) where !i.GetParameters().Any() select i; var resultsSet = new IList <ConstructorInfo>[] { ctorComponent.Query(typeof(StringBuilder), new {}, flags).ToList(), ctorComponent.Query(typeof(StringBuilder), new {}).ToList(), ctorComponent.Query(strBuilder, new {}, flags).ToList(), ctorComponent.Query(strBuilder, new {}).ToList(), new[] { ctorComponent.Parameterless(typeof(StringBuilder)) }, new[] { ctorComponent.Parameterless(strBuilder) }, new[] { ctorComponent.Parameterless(typeof(StringBuilder), flags) }, new[] { ctorComponent.Parameterless(strBuilder, flags) }, }; //expecting should only be one foreach (var results in resultsSet) { Assert.AreEqual(1, results.Count()); Assert.AreEqual(expecting.First(), results.First()); } Assert.IsTrue(ctorComponent.HasParameterless(strBuilder)); Assert.IsTrue(ctorComponent.HasParameterless(strBuilder, flags)); }
public static List <PropertyComponent> CreatePropertyComponents(string filePath) { List <PropertyComponent> propertyComponents = new List <PropertyComponent>(); var propertyLines = FileHelpers.GetPropertyLinesFromFile(filePath); var nameSpaceLine = propertyLines.Where(x => x.Contains("namespace")).FirstOrDefault(); if (nameSpaceLine != null) { var nameSpace = nameSpaceLine.Replace("namespace ", ""); propertyComponents.Add(new PropertyComponent { Name = nameSpace.Substring(0, nameSpace.IndexOf(".Domain")), IsNamespace = true }); } if (File.ReadAllText(filePath).Contains("AuditedEntity")) { propertyComponents.Add(new PropertyComponent { Name = "Id", PropertyType = PropertyType.Number, PropertyTypeString = "int" }); } foreach (var propertyLine in propertyLines) { PropertyComponent propertyComponent = Property.GetComponentsFromLine(propertyLine); if (propertyComponent != null) { propertyComponents.Add(propertyComponent); } } // Writer.WriteAllDtos(OutputDirectory, FileName, propertyComponents); return(propertyComponents); }
//AI是长期组件,但是每回合只执行一次 public override void Init(List <BasicEntity> entities) { turnNumber = StateStaticComponent.m_turneNumber; base.Init(entities); foreach (BasicEntity e in entities) { PropertyComponent propertyComp = (PropertyComponent)e.GetSpecicalComponent(ComponentType.Property); if (propertyComp.m_characterType == PropertyComponent.CharacterType.Heretic) { AIComponent aiComp = (AIComponent)e.GetSpecicalComponent(ComponentType.AI); aiComp.m_enemy = new Heretic(e); aiComp.m_patrolPoint = propertyComp.m_patrolPoint; Heretic heretic = (Heretic)aiComp.m_enemy; heretic.m_events.AddEvent(AIComponent.Decision.Patrol); heretic.m_events.m_events [0].m_usingActionPoint = 0; PatrolDecision <Heretic> a = (PatrolDecision <Heretic>)heretic.m_decisions [AIComponent.Decision.Patrol]; a.m_tmpHp = propertyComp.HP; continue; } } }
private static void DoFunctionalConstructorTest <T>(T instance, Func <ConstructorInfo, bool> filter, object[] paramQueryArgs, BindingFlags flags) { var cacheComponent = new CacheComponent(new Underscore.Function.CompactComponent(), new Underscore.Utility.CompactComponent()); var propComponent = new PropertyComponent(); var ctorComponent = new ConstructorComponent(cacheComponent, propComponent); var expectedToHave = new HashSet <ConstructorInfo>(typeof(T).GetConstructors(flags).Where(filter)); var testingqtypenf = _.Function.Partial <Type, object, IEnumerable <ConstructorInfo> >( ctorComponent.Query, typeof(T) ); var testingqtypewf = _.Function.Partial <Type, object, BindingFlags, IEnumerable <ConstructorInfo> >( ctorComponent.Query, typeof(T) ); var testingqobjwf = _.Function.Partial <object, object, BindingFlags, IEnumerable <ConstructorInfo> >(ctorComponent.Query, instance); var resultSet = paramQueryArgs.Select(testingqtypenf) .Concat(paramQueryArgs.Select(a => testingqtypewf(a, flags))) .Concat(paramQueryArgs.Select(a => testingqobjwf(a, flags))) .Concat(paramQueryArgs.Select(a => testingqobjwf(a, flags))); int i = 0; foreach (var result in resultSet) { Assert.IsTrue(result.All(expectedToHave.Contains), string.Join(", ", result.Select(a => "(" + string.Join(" , ", a.GetParameters().Select(b => b.Name + ":" + b.ParameterType.Name)) + ")")) + " Invocation " + i); i++; } }
//实例化方块 void Draw() { string id = brush.m_blockID.ToString(); //获取笔刷位置 float posX = brush.transform.position.x; float posY = brush.transform.position.y; float poxZ = brush.transform.position.z; Debug.Log("voxelMap.name: " + voxelMap.name); if (voxelMap.displayUpperGizmo) { GameObject block = GameObject.Find(voxelMap.name + "/voxelUpperBlocks/block_" + id); //如果找不到现有的实例,则新建一个方块 if (block == null) { block = new GameObject("block_" + id); block.transform.SetParent(voxelMap.voxelUpperBlocks.transform); block.transform.position = new Vector3(posX, posY, poxZ); block.AddComponent <MeshFilter> (); block.AddComponent <MeshRenderer> (); block.AddComponent <BasicEntity> (); block.AddComponent <BlockInfoComponent> (); block.AddComponent <PropertyComponent> (); //block.AddComponent<AbilityComponent> (); } block.tag = brush.m_tag; //传入方块的网格数据 BlockInfoComponent blockInfoComponent = block.GetComponent <BlockInfoComponent> (); PropertyComponent propertyComponent = block.GetComponent <PropertyComponent> (); //AbilityComponent abilityComponent = block.GetComponent<AbilityComponent> (); block.GetComponent <MeshFilter> ().sharedMesh = brush.m_meshFilter.sharedMesh; block.GetComponent <MeshRenderer> ().sharedMaterial = brush.m_meshRender.sharedMaterial; // blockInfoComponent.m_blockType = voxelMap.GetBlockBrush.BlockType; blockInfoComponent.m_blockName = voxelMap.GetBlockBrush.m_name; blockInfoComponent.m_logicPosition = brush.m_LogicPosition; blockInfoComponent.m_componentType = ComponentType.BlockInfo; blockInfoComponent.m_entity = block.GetComponent <BasicEntity> (); propertyComponent.m_componentType = ComponentType.Property; propertyComponent.m_entity = block.GetComponent <BasicEntity> (); //abilityComponent.m_componentType = ComponentType.Ability; //abilityComponent.m_entity = block.GetComponent<BasicEntity> (); } else { GameObject block = GameObject.Find(voxelMap.name + "/voxelLowerBlocks/block_" + id); //如果找不到现有的实例,则新建一个方块 if (block == null) { block = new GameObject("block_" + id); block.transform.SetParent(voxelMap.voxelLowerBlocks.transform); block.transform.position = new Vector3(posX, posY, poxZ); block.AddComponent <MeshFilter> (); block.AddComponent <MeshRenderer> (); block.AddComponent <BasicEntity> (); block.AddComponent <BlockInfoComponent> (); block.AddComponent <PropertyComponent> (); //block.AddComponent<AbilityComponent> (); } block.tag = brush.m_tag; //传入方块的网格数据 BlockInfoComponent blockInfoComponent = block.GetComponent <BlockInfoComponent> (); PropertyComponent propertyComponent = block.GetComponent <PropertyComponent> (); //AbilityComponent abilityComponent = block.GetComponent<AbilityComponent> (); block.GetComponent <MeshFilter> ().sharedMesh = brush.m_meshFilter.sharedMesh; block.GetComponent <MeshRenderer> ().sharedMaterial = brush.m_meshRender.sharedMaterial; // blockInfoComponent.m_blockType = voxelMap.GetBlockBrush.BlockType; blockInfoComponent.m_blockName = voxelMap.GetBlockBrush.m_name; blockInfoComponent.m_logicPosition = brush.m_LogicPosition; blockInfoComponent.m_componentType = ComponentType.BlockInfo; blockInfoComponent.m_entity = block.GetComponent <BasicEntity> (); propertyComponent.m_componentType = ComponentType.Property; propertyComponent.m_entity = block.GetComponent <BasicEntity> (); //abilityComponent.m_componentType = ComponentType.Ability; //abilityComponent.m_entity = block.GetComponent<BasicEntity> (); } //Debug.Log (voxelMap.name + "/voxelLowerBlocks"); //GameObject voxelLowerBlocks = GameObject.Find (voxelMap.name + "/voxelLowerBlocks"); //voxelLowerBlocks.GetComponent<VoxelBlocks> ().mapData.Add (new Vector3 (1, 1, 1), BlockType.Door); }
//添加某一类型的组件 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 PropertyComponentViewModel(PropertyComponent propertyComponent) : base(propertyComponent) { this.PropertyComponent = propertyComponent; }
protected void WalkElements(CodeElement cein, AbstractComponent parent) { CodeElements ces; switch (cein.Kind) { // Handle namespaces case EnvDTE.vsCMElement.vsCMElementNamespace: { CodeNamespace cn = (CodeNamespace)cein; ces = cn.Members; foreach (CodeElement ce in ces) { WalkElements(ce, parent); } break; } // Handle classes case EnvDTE.vsCMElement.vsCMElementClass: { CodeClass cc = (CodeClass)cein; ClassComponent cls = new ClassComponent(cc.FullName, cc.Name); cls.CodeClass = cc; parent.Visit(cls); ces = cc.Members; foreach (CodeElement ce in ces) { WalkElements(ce, cls); } break; } // Handle interfaces case EnvDTE.vsCMElement.vsCMElementInterface: { CodeInterface ci = (CodeInterface)cein; // nothing for now. break; } // Handle methods (functions) case EnvDTE.vsCMElement.vsCMElementFunction: { CodeFunction cf = (CodeFunction)cein; MethodComponent mc = new MethodComponent(cf.FullName, cf.Name); parent.Visit(mc); mc.CreateRepresentation(GetFunctionText(cf)); mc.CodeFunction = cf; break; } // Handle properties case EnvDTE.vsCMElement.vsCMElementProperty: { CodeProperty cp = (CodeProperty)cein; PropertyComponent pc = new PropertyComponent(cp.FullName, cp.Name); parent.Visit(pc); break; } // Handle fields (variables) case EnvDTE.vsCMElement.vsCMElementVariable: { CodeVariable cv = (CodeVariable)cein; FieldComponent fc = new FieldComponent(cv.FullName, cv.Name); parent.Visit(fc); break; } } }
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; }