void Start() { List <Texture2D> texs = new List <Texture2D>(); foreach (var s in shots) { Texture2D[] ts; s.GetTextures(out ts); texs.AddRange(ts); } Material mat = new Material(sh); TextureAtlas ta = new TextureAtlas(texs.ToArray()); mat.mainTexture = ta.atlas; foreach (var s in shots) { s.material = mat; s.SetTextures(ta); } BattleBehaviour.AddEvent(() => { foreach (var s in shots) { s.Begin(); } }); }
public AIDriver(ShipTeam team) : base(team) { BattleBehaviour.AddEvent(() => { behaviours = team.behaviours; _behaviourWeights = new float[behaviours.Length]; }); enemies = new FastList <ShipController>(firePoints.maxPoints); }
protected override void OnSetShip() { BattleBehaviour.AddEvent(() => { ship.team.myTeam = true; if (ui == null) { ui = GameObject.FindObjectOfType <PlayerUIManager>(); ui.GetRadar().SetDriver(this); uiBehaviour = ScreenManager.GetScreen <PlayerUIBehaviour>(); } var shipSystem = ship.shipSystem; ski = new ShipKeyInput(shipSystem); //Get camera from watcher watcher = GameObject.FindObjectOfType <WatcherBehaviour>(); watcher.target = ship.transform; camera = watcher.GetCamera(); //reset ui.SetAimPosition(aimPoint); everyTimeFire = false; everyTimeRotate = true; lockedEnemy = null; //SetAim(new Vector2(.5f, .7f)); BattleBehaviour.current.audioPlayer.SetListener(ship.transform); // audioPlayer is not initialized on start }); }
void OnDisable() //When ship is waiting for Destroy invoke { if (alive && BattleBehaviour.isBattleNow) //if disabling by not self { BattleBehaviour.AddEvent(Destroy); //Because can't change parent while disabling/activating } }
public static void CreateNew(BattleBehaviour world) { GameObject point0 = new GameObject("point0"); point0.AddComponent <DrawPoint>(); point0.transform.parent = world.transform; }
public void Destroy(int framesTo, float timeTo) { if (notWaitingForDestroy) { notWaitingForDestroy = false; BattleBehaviour.AddEvent(() => DestroyImmediate(), framesTo, timeTo); } }
/// <summary> /// Looks for enemies in adjecent nodes and creates a battle event if it finds any, adding the located enemies. /// </summary> void CheckLocalNodes() { foreach (Node _node in BarracksUnitNode.adjecant) { if (_node.navigability == nodeTypes.enemyUnit) { //If it detects an enemy group in any adjecent nodes, start combat if (_node.hex.transform.GetChild(0).TryGetComponent <EnemyBehaviour>(out EnemyBehaviour _enemy)) { //If the enemy is currently destroying a wall, stop it from doing so. if (_enemy.inSiege == true) { Destroy(_enemy.gameObject.GetComponent <SiegeBehaviour>()); _enemy.inSiege = false; } if (_enemy.inCombat == false) { List <Unit> _friendlyUnits = new List <Unit>(); List <Unit> _enemyUnits = new List <Unit>(); for (int i = 0; i < m_units.Count; i++) { if (m_units[i] != null) { if (m_units[i].TryGetComponent(out UnitComponent _unitComp)) { _friendlyUnits.Add(_unitComp.unit); } } } for (int i = 0; i < _enemy.m_units.Count; i++) { if (_enemy.m_units[i] != null) { if (_enemy.m_units[i].TryGetComponent(out UnitComponent _unitComp)) { _enemyUnits.Add(_unitComp.unit); } } } BattleBehaviour _battle = this.gameObject.AddComponent <BattleBehaviour>(); _battle.StartBattle(_friendlyUnits, _enemyUnits); _battle.friendlyGroups.Add(this); _battle.enemyGroups.Add(_enemy); _enemy.inCombat = true; inCombat = true; } } else { return; } } } }
public override void OnDead() { camera.GetComponentInParent <CameraShaker>().Stop(); BattleBehaviour.AddEvent(watcher.ReleaseCamera, 1); BattleBehaviour.current.audioPlayer.SetListener(null); ScreenManager.currentManager.MoveTo("DeadView"); }
void DestroyImmediate() { //Sending destroy message to all systems BattleBehaviour.current.DestroyShip(this, 0, 0); //Deataching explosins in OnDisable message gameObject.SetActive(false); foreach (var c in components) { c.gameObject.SetActive(false); } //Final destroying the ship BattleBehaviour.AddEvent(() => { Destroy(gameObject); foreach (var c in components) { Destroy(c.gameObject); } }, 2); }
/// <summary> /// Funcion para manejar los turnos /// </summary> public void TurnManager() { if (turnCounter != characters.Length) { currentChar = characters[turnCounter].GetComponent <BattleBehaviour>(); } else { turnCounter = 0; } if (currentChar.isEnemy != true) { combatUi.SetActive(true); } else { combatUi.SetActive(false); startCombat(); } //camera follow for characters camera.GetComponent <Follow>().setFollow(characters[turnCounter]); }
/// <summary> /// Adds an enemy to the Battle if they're not already in it. /// </summary> void AddEnemyToBattle() { foreach (Node _node in BarracksUnitNode.adjecant) { if (_node.navigability == nodeTypes.enemyUnit) { //If it detects an enemy group in any adjecent nodes, get all of the units from that enemy group EnemyBehaviour _enemy = _node.hex.transform.GetChild(0).GetComponent <EnemyBehaviour>(); if (_enemy.inCombat == false) { BattleBehaviour _battle = this.gameObject.GetComponent <BattleBehaviour>(); List <Unit> _enemyUnits = new List <Unit>(); foreach (GameObject _gameObj in _enemy.m_units) { _enemyUnits.Add(_gameObj.GetComponent <UnitComponent>().unit); } bool _groupAlreadyInBattle = false; foreach (Unit _enemyUnit in _enemyUnits) { //If the incoming enemy is already in the battle, it should't be added into the list. if (_battle.enemyUnits.Contains(_enemyUnit)) { _groupAlreadyInBattle = true; } } if (_groupAlreadyInBattle == false) { _battle.JoinBattle(_enemyUnits); _battle.enemyGroups.Add(_enemy); _enemy.inCombat = true; } } } } }
public BattleAgent(Character baseCharacter, BattleBehaviour behaviour) { BaseCharacter = baseCharacter; m_DefaultBehaviour = behaviour; HP = this["HP"]; SP = this["SP"]; foreach (Skill skill in BaseCharacter.ActiveSkills) { if (this["Skill: " + skill.Type] == 0) { this["Skill: " + skill.Type] = 1; } } foreach (Status status in BaseCharacter.PassiveSkills) { if (status != null) { Inflict(status, int.MaxValue, new BattleQueueTime(float.NegativeInfinity, 0f)); } } }
public void takeTurnAI() { //code for enemy AI to determine action List <BattleBehaviour> plausbile = new List <BattleBehaviour>(); foreach (BattleBehaviour bb in behaviours) { bool test = testCondition(bb); if (test) { plausbile.Add(bb); } /* * if (bb.condition == BattleCondition.TURN_NUMBER) { * if (bf.turnCount == bb.value) { * highestPriority = bb; * break; * } * }else{ * if (bb.condition == BattleCondition.TURN_EVEN || bb.condition == BattleCondition.TURN_ODD) { * highestPriority = bb; * }else{ * if (bb.condition == BattleCondition.ANY_TURN) { * * } * } * } */ } List <BattleBehaviour> highestPrioritys = new List <BattleBehaviour>(); int topPriority = 0; foreach (BattleBehaviour bb in plausbile) { if (bb.priority > topPriority) { highestPrioritys.Clear(); topPriority = bb.priority; highestPrioritys.Add(bb); } else if (bb.priority == topPriority) { highestPrioritys.Add(bb); } } BattleBehaviour finalChoice = null; if (highestPrioritys.Count > 1) { finalChoice = highestPrioritys[Mathf.FloorToInt(Random.Range(0, highestPrioritys.Count - 1))]; } else if (highestPrioritys.Count == 1) { finalChoice = highestPrioritys[0]; } else if (highestPrioritys.Count < 1) { Debug.Log("No skills were found for enemy to use!"); } if (finalChoice != null) { Skill skillUsing = getOwnedSkill(finalChoice.skillName); if (skillUsing != null) { if (skillUsing.targetType == TargetType.ALL_TARGET) { bf.targetEntireParty(); } else if (skillUsing.targetType == TargetType.TARGET) { BattleTarget myTar = getHighestThreat().target; while (myTar.actor.GetComponent <Actor>()._base.curHealth < 0) { myTar = targets[Mathf.FloorToInt(Random.Range(0, targets.Count - 1))].target; } bf.targetSingle(myTar); } else if (skillUsing.targetType == TargetType.SELF) { bf.targetSelf(); } else if (skillUsing.targetType == TargetType.ALL_PARTY) { bf.targetEntireEnemies(); } else if (skillUsing.targetType == TargetType.PARTY_MEMBER) { } bf.curSkill = skillUsing; bf.executeSkill(); } else { Debug.LogError("Skill was not found in actor's owned skills list!"); } } else { Debug.LogError(_base.name + " was unable to find a command!"); } }
public static void Decode(AssetBundle assetBundle, BattleBehaviour world) { //BattleSysData sysData = assetBundle.mainAsset as BattleSysData; //GameObject tmpGObj; //EyePointsSys eyePointsSys; //BattleProgressSysData progressSysData; //EyePathData ProgressData; //BattleModelSysData modelSysData; //EnemyData modelData; //world.BattleId = sysData.battleId; //world.EyePostions = new Transform[sysData.eyePoints.Length]; //world.ProgressDatas = new EyePathData[sysData.eyePointDatas.Length]; //world.EnemyDatas = new EnemyData[sysData.modelDatas.Length]; //world.DefaultSpeed = sysData.defaultSpeed; //int i; //for (i = 0; i < sysData.eyePoints.Length; i++) //{ // eyePointsSys = sysData.eyePoints[i]; // //重复引用的transform会多次创建 TO DO // tmpGObj = new GameObject("point" + i); // tmpGObj.transform.parent = world.transform; // tmpGObj.transform.position = eyePointsSys.position; // tmpGObj.transform.forward = eyePointsSys.direction; // tmpGObj.AddComponent<DrawPoint>(); // world.EyePostions[i] = tmpGObj.transform; //} //for (i = 0; i < sysData.eyePointDatas.Length; i++) //{ // progressSysData = sysData.eyePointDatas[i]; // ProgressData = new EyePathData(); // ProgressData.startPointIndex = progressSysData.startPointIndex; // ProgressData.endPointIndex = progressSysData.endPointIndex; // ProgressData.speed = progressSysData.speed; // world.ProgressDatas[i] = ProgressData; //} ////没有进度数据,则把所有的地图点当做一个进度 //if (world.ProgressDatas.Length == 0) //{ // world.ProgressDatas = new EyePathData[1]; // ProgressData = new EyePathData(); // ProgressData.startPointIndex = 0; // ProgressData.speed = sysData.defaultSpeed; // world.ProgressDatas[0] = ProgressData; //} //for (i = 0; i < sysData.modelDatas.Length; i++) //{ // modelSysData = sysData.modelDatas[i]; // //保持prefab的链接 // tmpGObj = CreatePrefabGObj(modelSysData.prefabName); // tmpGObj.name = modelSysData.name; // tmpGObj.transform.localScale = modelSysData.scale; // tmpGObj.transform.position = modelSysData.position; // tmpGObj.transform.forward = modelSysData.direction; // tmpGObj.transform.parent = world.transform; // modelData = new EnemyData(); // modelData.Enemy = tmpGObj.transform; // modelData.type = (BattleModelType)modelSysData.type; // world.EnemyDatas[i] = modelData; //} }
/// <summary> /// 只用在editor中 /// </summary> /// <param name="world"></param> public static void Encode(BattleBehaviour world) { //EyePointsSys[] eyePoints = new EyePointsSys[world.EyePostions.Length]; //BattleProgressSysData[] eyePointDatas = new BattleProgressSysData[world.ProgressDatas.Length]; //BattleModelSysData[] modelSysDatas = new BattleModelSysData[world.EnemyDatas.Length]; //int i; //BattleProgressSysData progressSysData; //EyePathData progressData; //EyePathData progressNextData; //for (i = 0; i < world.EyePostions.Length; i++) //{ // Transform t = world.EyePostions[i]; // EyePointsSys eyePoint = new EyePointsSys(); // eyePoint.position = t.position; // eyePoint.direction = t.forward; // eyePoints[i] = eyePoint; //} //for (i = 0; i < world.ProgressDatas.Length; i++) //{ // progressSysData = new BattleProgressSysData(); // progressData = world.ProgressDatas[i]; // progressSysData.speed = progressData.speed; // progressSysData.startPointIndex = progressData.startPointIndex; // if (i == world.ProgressDatas.Length - 1) // { // progressSysData.endPointIndex = eyePoints.Length - 1; // } // else // { // progressNextData = world.ProgressDatas[i + 1]; // progressSysData.endPointIndex = progressNextData.startPointIndex; // } // eyePointDatas[i] = progressSysData; //} //for (i = 0; i < world.EnemyDatas.Length; i++) //{ // EnemyData modelData = world.EnemyDatas[i]; // BattleModelSysData modelSysData = new BattleModelSysData(); // modelSysData.position = modelData.Enemy.position; // modelSysData.direction = modelData.Enemy.forward; // modelSysData.scale = modelData.Enemy.localScale; // modelSysData.type = (int)modelData.type; // modelSysData.prefabName = modelData.prefabName; // modelSysData.name = modelData.Enemy.name; // modelSysDatas[i] = modelSysData; //} //BattleSysData sysData = ScriptableObject.CreateInstance<BattleSysData>(); //sysData.eyePointDatas = eyePointDatas; //sysData.eyePoints = eyePoints; //sysData.battleId = world.BattleId; //sysData.defaultSpeed = world.DefaultSpeed; //sysData.modelDatas = modelSysDatas; //string fileName = sysData.battleId; //string path = "Assets/tmp_" + fileName + ".asset"; //AssetDatabase.CreateAsset(sysData, path); //Object o = AssetDatabase.LoadAssetAtPath(path, typeof(BattleSysData)); ////过时? //BuildPipeline.BuildAssetBundle(o, null, Application.dataPath + "/StreamingAssets/" + fileName + ".assetbundle"); //AssetDatabase.DeleteAsset(path); //AssetDatabase.Refresh(); }
void Start() { // Load map XmlDocument mapDoc = new XmlDocument(); mapDoc.PreserveWhitespace = false; try { mapDoc.Load("Assets/Battle/Data/Maps/" + NextMapFile + ".xml"); XmlNode root = mapDoc.SelectSingleNode("map"); grid.info = root.SelectSingleNode("grid") as XmlElement; foreach (XmlElement battleInfo in root.SelectNodes("battle")) { if (battleInfo.GetAttribute("id").Equals(NextBattle)) { // Load agents BattleUnit.Reset(); foreach (XmlElement characterInfo in battleInfo.SelectNodes("character")) { try { string unit = characterInfo.HasAttribute("unit") ? characterInfo.GetAttribute("unit") : "civilian"; BattleBehaviour behaviour; if (characterInfo.HasAttribute("behaviour")) { behaviour = BattleBehaviour.Parse(characterInfo.GetAttribute("behaviour")); } else if (unit.Equals("player")) { behaviour = null; } else if (unit.Equals("civilian")) { behaviour = null; // TODO run away } else { behaviour = new BattleOffensiveBehaviour(); } Character character = AssetHolder.Characters[characterInfo.GetAttribute("name")]; BattleAgent agent = new BattleAgent(character, behaviour); agent.Coordinates = new Vector2Int( int.Parse(characterInfo.GetAttribute("x")), int.Parse(characterInfo.GetAttribute("y")) ); agent.Unit = BattleUnit.Get(unit); agents.Add(agent); BattleTile tile = grid[agent.Coordinates]; BattleActor actor = Instantiate <BattleActor>((BattleActor)AssetHolder.Objects["actor"], tile.ground.transform); actor.Agent = agent; tile.Actor = actor; } catch (System.Exception e) { Debug.Log(e); // TODO } } // Load cutscenes m_Cutscenes = new Dictionary <string, BattleAction>(); foreach (XmlElement cutsceneInfo in battleInfo.SelectNodes("cutscene")) { try { List <BattleAction> cutsceneSequence = new List <BattleAction>(); foreach (XmlNode sceneInfoNode in cutsceneInfo.ChildNodes) { XmlElement sceneInfo = sceneInfoNode as XmlElement; if (sceneInfo != null) { if (sceneInfo.Name.Equals("move")) { string character = sceneInfo.GetAttribute("character"); BattleAgent target = null; foreach (BattleAgent agent in agents) { if (agent.BaseCharacter.Name.Equals(character)) { target = agent; break; } } if (target != null) { cutsceneSequence.Add( new BattleMoveAction( target, new Vector2Int( int.Parse(sceneInfo.GetAttribute("x")), int.Parse(sceneInfo.GetAttribute("y")) ) ) ); } } else if (sceneInfo.Name.Equals("text")) { string character = sceneInfo.GetAttribute("character"); BattleAgent target = null; foreach (BattleAgent agent in agents) { if (agent.BaseCharacter.Name.Equals(character)) { target = agent; break; } } if (target != null) { cutsceneSequence.Add( new BattleDialogueAction(target, sceneInfo.InnerText.Trim()) ); } } } } m_Cutscenes.Add(cutsceneInfo.GetAttribute("trigger"), new BattleSequenceAction(cutsceneSequence)); } catch (System.Exception e) { Debug.Log(e); } } } } BattleAgentUI.Shown = false; BattleSelector.Shown = false; } catch (System.Exception e) { Debug.Log(e); // TODO } }
public bool testCondition(BattleBehaviour bb) { bool testPassed = true; for (int i = 0; i < bb.conditions.Length - 1; i++) { if (_base.curMana < getOwnedSkill(bb.skillName).cost) { testPassed = false; break; } else if (bb.conditions[i] == BattleCondition.TURN_NUMBER) { if (bf.turnCount != bb.values[i]) { testPassed = false; break; } } else if (bb.conditions[i] == BattleCondition.TURN_EVEN || bb.conditions[i] == BattleCondition.TURN_ODD) { if (bb.conditions[i] == BattleCondition.TURN_EVEN) { //EVEN if (bf.turnCount % 2 != 0) { testPassed = false; break; } } else { //ODD if (bf.turnCount % 2 != 1) { testPassed = false; break; } } } else if (bb.conditions[i] == BattleCondition.HEALTH) { if (_base.curHealth > bb.values[i]) { testPassed = false; break; } } else if (bb.conditions[i] == BattleCondition.MANA) { if (_base.curHealth > bb.values[i]) { testPassed = false; break; } } else if (bb.conditions[i] == BattleCondition.ENEMY_ELE) { if (getOwnedSkill(bb.skillName).element == getHighestThreat().target.actor.GetComponent <Actor>()._base.myElement) { testPassed = false; break; } } } return(testPassed); }