public void StartGame() { foreach (HouseScript house in Houses) { for (int i = 0; i < Humans; i++) { GameObject human = Instantiate(Human, house.transform.position, Quaternion.identity, HumansContainer); HumanBeingScript hbs = human.GetComponent <HumanBeingScript>(); human.GetComponent <MeshFilter>().sharedMesh = HumanMesh; HumansList.Add(hbs); hbs.HouseType = house.HouseType; hbs.TargetHouse = house.transform; hbs.FinallyBackHome += Hbs_FinallyBackHome; hbs.OwnHouse = house.GetComponent <HouseScript>(); } } for (int i = 0; i < FoodPerDay; i++) { GameObject food = Instantiate(Food, FoodContainer); food.GetComponent <MeshFilter>().sharedMesh = FoodMesh; food.GetComponent <MeshRenderer>().sharedMaterial = FoodMaterial; food.SetActive(false); FoodsList.Add(food.GetComponent <FoodScript>()); } GroundScript.Instance.RunTimeBake(); }
private IEnumerator FollowEnemy(Transform humanT) { bool EnemyAlive = true; HumanBeingScript Enemy = humanT.GetComponent <HumanBeingScript>(); while (EnemyAlive) { GoToPosition(humanT.position); float Dist = Vector3.Distance(transform.position, humanT.position); if (Dist < 1f && CanIAttack) { CanIAttack = false; Invoke("AttackAction", 1); Enemy.UnderAttack(Attack); } if (!Enemy.gameObject.activeInHierarchy || Enemy.CurrentState == StateType.Home) { EnemyAlive = false; } yield return(new WaitForEndOfFrame()); } CurrentState = StateType.ComingBackHome; GoToPosition(TargetHouse.position); }
private void MeetOthers(Collider other) { if (CurrentAction == ActionState.None && CurrentState != StateType.Home) { HumanBeingScript human = other.GetComponent <HumanBeingScript>(); if (HouseType != human.HouseType) { ActionState CurrentEnemyAction = human.GetCurrentAction(this); GetCurrentAction(human); switch (CurrentAction) { case ActionState.None: break; case ActionState.Charity: switch (CurrentEnemyAction) { case ActionState.Begging: human.Food += (Food / 100) * GivingPerc + (Food / 100) * GratitiudeFoodPerc; Food -= (Food / 100) * GivingPerc - (Food / 100) * CharityFoodPerc; break; } Invoke("ResetAction", 5); break; case ActionState.Begging: Invoke("ResetAction", 5); break; case ActionState.Fight: switch (CurrentEnemyAction) { case ActionState.Charity: AttackEnemy(human.transform); break; case ActionState.Begging: Attack += (Attack / 100) * HateGratitutePerc; AttackEnemy(human.transform); break; case ActionState.Fight: Attack += (Attack / 100) * HateHatePerc; AttackEnemy(human.transform); break; } break; } } } }
public void Reproduction(Transform home) { for (int i = 0; i < MaxNumChildren; i++) { GameObject human = Instantiate(Human, home.position, Quaternion.identity, HumansContainer); HumanBeingScript hbs = human.GetComponent <HumanBeingScript>(); HumansList.Add(hbs); hbs.TargetHouse = home; hbs.FinallyBackHome += Hbs_FinallyBackHome; hbs.OwnHouse = home.GetComponent <HouseScript>(); ReproducedLastDay++; } }
public ActionState GetCurrentAction(HumanBeingScript enemy) { if (CurrentAction == ActionState.None && CurrentState != StateType.Home) { if (DidIFindFood) { if (enemy.DidIFindFood) { float AttackPerc = (Hate * 100) / (Charity + Hate); CurrentAction = Random.Range(0, 99) < AttackPerc ? ActionState.Fight : ActionState.Charity; } else { float CharityPerc = (Hate * 100) / (Charity + Hate); CurrentAction = Random.Range(0, 99) < CharityPerc ? ActionState.Charity : ActionState.Fight; } } else { if (enemy.DidIFindFood) { float AttackPerc = (Hate * 100) / (Gratitude + Hate); CurrentAction = Random.Range(0, 99) < AttackPerc ? ActionState.Fight : ActionState.Begging; } else { CurrentAction = ActionState.None; } } switch (CurrentAction) { case ActionState.Charity: Charity += CModifier; Gratitude += CGModifier; Hate += CHModifier; BaseHp += CModifierHealth; Speed += CModifierSpeed; Attack += CModifierAttack; MR.material = CharityM; break; case ActionState.Begging: Gratitude += GModifier; Charity += GCModifier; Hate += GHModifier; BaseHp += GModifierHealth; Speed += GModifierSpeed; Attack += GModifierAttack; MR.material = BegM; break; case ActionState.Fight: Hate += HModifier; Gratitude += HGModifier; Charity += HCModifier; BaseHp += HModifierHealth; Speed += HModifierSpeed; Attack += HModifierAttack; MR.material = AttackM; break; } } return(CurrentAction); }