internal static void Continue(SynchronizedActor actor, int actionCost) { if (Instance.m_started) { actor.ActionTime += (ulong)actionCost; actor.EndTurn(); //Debug.Log(actor.name + " Action Complete, Next Action Time: "+actor.ActionTime); SynchronizedActor next = Instance.GetNextActorTurn(); int count = 100; while (next == null && count > 0) { count--; Instance.ForwardTime(); next = Instance.GetNextActorTurn(); } if (count == 0) { Debug.LogError("Continue Loop Timeout!"); } else { //Debug.Log("Giving Turn to " + next.name); next.GiveTurn(); } } }
public static void Spawn(int x, int y, GameObject prefab) { World.Grid grid = World.Instance.GetGrid(); World.Cell cell = grid.GetCell(x, y); if (!cell.IsBlocked) { //Vector3 position = new Vector3(x, heightOffset, y); GameObject spawn = Instantiate <GameObject>(prefab); spawn.transform.position = spawn.transform.position; SynchronizedActor actor = spawn.GetComponent <SynchronizedActor>(); if (actor != null) { Entity entity = null; if (actor.tag == "Player") { entity = new Player(x, y, EntityStatistics.GetRandomPlayerStats()); } else if (actor.tag == "Enemy") { MonsterConfig config = spawn.GetComponent <MonsterConfig>(); entity = new Monster(x, y, config.GetStats()); } if (entity != null) { actor.InitActor(entity); } } } }
private void kill(SynchronizedActor actor) { if (!m_started) { return; } for (int i = 0; i < m_actorList.Count; i++) { if (actor == m_actorList[i]) { m_actorList.RemoveAt(i); break; } } Entity e = actor.Entity; actor.Entity.GetCell().SetEntity(null); actor.gameObject.SetActive(false); if (e.GetType() == typeof(Player)) { m_player = null; if (OnPlayerDiedEvent != null) { OnPlayerDiedEvent(); } } else if (m_actorList.Count == 1) // only player remains { if (OnAllEnemiesDiedEvent != null) { OnAllEnemiesDiedEvent(); } } }
// Use this for initialization void Start() { m_actor = GetComponent <SynchronizedActor>(); if (m_actor == null) { m_actor = gameObject.AddComponent <SynchronizedActor>(); } }
// Use this for initialization void Start() { m_movingEntity = GetComponent <MovingEntity>(); m_attackingEntity = GetComponent <AttackingEntity>(); m_actor = GetComponent <SynchronizedActor>(); m_levelBuilder = FindObjectOfType <LevelBuilder>(); m_actor.OnTurnStatusChange += actor_OnTurnStatusChange; }
// Use this for initialization void Start() { m_lastRotationUpdate = transform.rotation; m_lastPositionUpdate = transform.position; m_syncActor = GetComponent <SynchronizedActor>(); if (m_syncActor == null) { m_syncActor = gameObject.AddComponent <SynchronizedActor>(); } }
// Use this for initialization1 void Start() { m_actor = GetComponent <SynchronizedActor>(); m_enemyController = GetComponent <EnemyController>(); m_actor.Stats.OnStatsChangedEvent += RefreshString; GameObject canvas = GameObject.Find("_canvas"); m_printer = Instantiate(Resources.Load <GameObject>("Prefabs/EntityStatsText")); m_printer.transform.SetParent(canvas.transform); RefreshString(); }
public static void Start() { Instance.m_started = true; Instance.init(); SynchronizedActor a = Instance.GetNextActorTurn(); if (a != null) { Debug.Log("Actor Found: " + a); a.GiveTurn(); } else { Debug.Log("Null Actor!"); } }
public static AttackingEntity.AttackResult Fight(SynchronizedActor actor, SynchronizedActor target) { Debug.Log("Begin Attack: " + actor.Stats.Name + " vs. " + target.Stats.Name); Entity tentity = target.Entity; int x, y; tentity.GetPosition(out x, out y); AttackingEntity.AttackResult ares = actor.AttackingEntity.Attack(x, y); if (ares != null && (ares.Result == AttackingEntity.AttackResult.ResultValue.Hit)) { int dmg = ares.Weapon.GetDamage(); tentity.Stats.Health -= dmg; tentity.Actor.Moan(dmg); } return(ares); }
private void init() { GameObject player = GameObject.FindGameObjectWithTag("Player"); m_player = player.GetComponent <SynchronizedActor>(); m_actorList.Add(m_player); GameObject[] enemas = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject go in enemas) { SynchronizedActor a = go.GetComponent <SynchronizedActor>(); if (a != null) { m_actorList.Add(a); } } Debug.Log("Actors loaded from scene: " + m_actorList.Count); }
/// <summary> /// Checks if theres anyone nearby within melee range and attacks. Return true if attack was made. /// Ranged attack not supported /// </summary> /// <returns></returns> private bool doAttack() { World.Grid grid = World.Instance.GetGrid(); int x, y; m_actor.Entity.GetPosition(out x, out y); World.Cell myCell = grid.GetCell(x, y); World.Cell[] neighbours = grid.GetNeighbours4(myCell); List <SynchronizedActor> pTargets = new List <SynchronizedActor>(); foreach (World.Cell cell in neighbours) { if (cell.ContainsEntity) { Entity e = cell.GetEntity(); if (e.GetType() == typeof(Player)) { pTargets.Add(e.Actor); break; } else if (UnityEngine.Random.value < Constants.FRIENDLY_FIRE_CHANCE) { pTargets.Add(e.Actor); } } } if (pTargets.Count > 0) { SynchronizedActor target = pTargets[UnityEngine.Random.Range(0, pTargets.Count)]; AttackingEntity.AttackResult result = CombatSolver.Fight(m_actor, target); if (result.Result == AttackingEntity.AttackResult.ResultValue.Hit || result.Result == AttackingEntity.AttackResult.ResultValue.Miss) { Synchronizer.Continue(m_actor, result.Weapon.TimeCost); } return(true); } return(false); }
internal static void KillEntity(SynchronizedActor actor) { Instance.kill(actor); }
// Use this for initialization void Start() { m_movingEntity = GetComponent <MovingEntity>(); m_actor = GetComponent <SynchronizedActor>(); m_actor.OnTurnStatusChange += OnTurnStatusChange; }
public IdleAction(SynchronizedActor actor, int timeStep) { m_actor = actor; m_idleDuration = timeStep; }