private void ChangeScene(Scene prev, Scene next) { if (!firstSectorStarted) { return; } //flooded loop for (int i = 0; i < floodedTiles.Count; i++) { Destroy(floodedTiles[i].gameObject); } floodedTiles.Clear(); string woodReport = ""; if (carpentersQuaters.isManned) { int crewRepairAmount = carpentersQuaters.tile.crewMem.endSectorRepairAmount; int needToRepair = (maxHealth - health) >= crewRepairAmount ? crewRepairAmount : maxHealth - health; int woodAvailableToUse = CanAfford(0, needToRepair, 0) ? needToRepair : wood; if (woodAvailableToUse > 0) { Spend(0, woodAvailableToUse, 0, false); Heal(woodAvailableToUse); woodReport += "Ship was repaired for " + woodAvailableToUse + " by using " + woodAvailableToUse + " wood. "; } } //food and doctor loop string doctorReport = ""; string foodReport = ""; if (doctorsQuaters.isManned) { for (int i = 0; i < crewMembers.Count; i++) { CrewMember c = crewMembers[i]; int healed = 0; bool starve = false; bool died = false; if (food > 0) { food = Mathf.Clamp(food - 2, 0, int.MaxValue); healed = c.Heal(doctorsQuaters.tile.crewMem.healingAbility); } else { starve = true; if (c.health < 4) { healed = c.Heal(doctorsQuaters.tile.crewMem.healingAbility); died = c.TakeDamage(4); } else { died = c.TakeDamage(4); healed = c.Heal(doctorsQuaters.tile.crewMem.healingAbility); } } if (healed > 0) { doctorReport += c.personName + " was healed for " + (healed) + ". "; } if (died) { foodReport += c.personName + " has died from starvation. "; i--; } else if (starve) { foodReport += c.personName + " has taken 4 damage due to starvation. "; } } } if (food == 0) { foodReport = "We have run out of food! " + foodReport; } else { foodReport = "We have used " + (crewMembers.Count * 2) + " food. "; } sectorEndReport = foodReport + doctorReport + woodReport; //TODO: training happen before stats updated maybe? for (int i = 0; i < crewMembers.Count; i++) { switch (crewMembers[i].role) { case CrewMember.Role.CAPTAIN: crewMembers[i].dexterity += 1; crewMembers[i].intelligence += 1; break; case CrewMember.Role.NAVIGATOR: case CrewMember.Role.DOCTOR: crewMembers[i].intelligence += 1; break; case CrewMember.Role.BAILER: case CrewMember.Role.CARPENTER: case CrewMember.Role.CANNONEER: crewMembers[i].dexterity += 1; break; } } }
void FixedUpdate() { if (printe) { PrintMethod(); printe = false; Debug.Break(); } if (battleManager != null) { if (role == Role.CANNONEER) { CrewMember priorityTarget = isPlayerCrew ? battleManager.GetNextOtherPriority() : battleManager.GetNextPlayerPriority(); if (target != priorityTarget) { target = priorityTarget; if (target) { BeginPath(AStar.FindPath(current, target.current, true)); couldFindPath = false; } } } } else { target = null; } Vector3 tilePos = current.transform.position; float distance = Vector2.Distance(transform.position, tilePos); bool onTilePrev = onTile; if (distance > MOVEMENT_ERROR_RANGE) { Vector3 pos = Vector3.Lerp(transform.position, tilePos, speed / distance * Time.fixedDeltaTime); pos.z = Z_VAL; transform.position = pos; onTile = false; } else { onTile = true; } if (target && path.Count > 0 && target.current != path.last.data) { BeginPath(AStar.FindPath(current, target.current, true)); couldFindPath = false; } if (path.Count > 0 && onTile) { path.RemoveFirst(); if (path.Count > 0) { if (path.first.data.crewMem) { if (path.first.data.crewMem == target) { return; } //Debug.Log (personName + " blocked"); bool cfpTemp; MyLinkedList <MovementTile> p = AStar.FindPath(current, target ? target.current : path.last.data, false, out cfpTemp); if (!target && !cfpTemp) { //... there's nothing here } else { BeginPath(p); couldFindPath = cfpTemp; if (path.Count > 1 && !path.first.next.data.crewMem) { path.RemoveFirst(); } } } if (path.Count > 0) { if (path.first.data.teleportLayerChange && current.teleportLayerChange && path.first.data.layer != current.layer) { Vector3 pos = path.first.data.transform.position; pos.z = Z_VAL; transform.position = pos; } ChangeCurrentTile(path.first.data); } } } if (path.Count == 0 && !target && ((shipPos && current == shipPos.tile) || (role == Role.BAILER && couldFindPath))) { currentAction = Action.IDLE; if (onTile && !onTilePrev) { timeOfLastAction = Time.time; } } if (target && path.Count == 0 && couldFindPath) { currentAction = Action.ATTACKING; } if (target && onTile && !couldFindPath && currentAction != Action.ATTACKING) { BeginPath(AStar.FindPath(current, target.current, false, out couldFindPath)); } if (shipPos && current != shipPos.tile && path.last.data != shipPos.tile && (!target || (role != Role.CANNONEER && target))) { BeginPath(AStar.FindPath(current, shipPos.tile, true)); if (target) { target = null; } } switch (currentAction) { case Action.IDLE: if (role == Role.BAILER) { //TODO: make dump face correct direction when picked up next to edge anim.SetInteger("Idle Action", hasWater ? 3 : 2); if (Time.time - timeOfLastAction > .5f) { if (!hasWater) { BeginPath(ship.GetShortestPathToEdgeTile(current)); current.floodedTile.Bail(); } else { ShipPosition bailPos = ship.GetClosestFloodedTile(current); ship.Assign(this, bailPos ? bailPos : ship.GetVacantPositionByPriority()); } timeOfLastAction = Time.time; hasWater = !hasWater; anim.SetBool("Has Water", hasWater); } } else if (role == Role.CARPENTER) { if (current.damagedTile) { anim.SetInteger("Idle Action", 1); if (Time.time - timeOfLastAction > repairSpeed) { timeOfLastAction = Time.time; if (current.damagedTile.Repair(repairAmount)) { DamagedPosition dp = ship.GetClosestDamagedTile(current); if (dp) { ship.Assign(this, dp); } else if (ship.carpentersQuaters && !ship.carpentersQuaters.isManned) { ship.Assign(this, ship.carpentersQuaters); } else { ship.Assign(this, ship.GetVacantPositionByPriority()); } } } } else { DamagedPosition dp = ship.GetClosestDamagedTile(current); if (dp) { ship.Assign(this, dp); } else { anim.SetInteger("Idle Action", 0); } } } else if (current.damagedTile) { anim.SetInteger("Idle Action", 1); //TODO: if repairing current position and job is changed or attack started for //cannoneer, reset damaged tile ismanned if (Time.time - timeOfLastAction > repairSpeed) { timeOfLastAction = Time.time; current.damagedTile.Repair(repairAmount); } current.damagedTile.isManned = true; } else { anim.SetInteger("Idle Action", 0); if (battleManager && role == Role.CANNONEER && current == shipPos.tile && Time.time - timeOfLastAction > cannonFireSpeed) { float rand = Random.Range(0f, 100f); ((CannonPosition)shipPos).Fire(battleManager, cannonHitChance > rand); timeOfLastAction = Time.time; } } break; case Action.WALKING: break; case Action.ATTACKING: //hopefully this only triggers on isalnd dwellers during an attack if (!target && !shipPos) { currentAction = Action.IDLE; } anim.SetInteger("FacingDirection", GetDirectionOfTile(target.current)); if (!target.target) { target.target = this; } if (Time.time - timeOfLastAction > attackSpeed) { timeOfLastAction = Time.time; target.TakeDamage(damage); } break; } anim.SetInteger("Action", (int)currentAction); Debug.DrawLine(transform.position, current.transform.position, Color.red); }