//환경 오브젝트 생성?? //알 생성(성별랜덤) public Egg LayEgg(Vector3 position) { var resource = Resources.Load("Prefabs/Food/egg"); if (resource == null) { Debug.Log("알이 없어.."); return(null); } GameObject objectBase = Instantiate(resource, position, Quaternion.identity) as GameObject; string objID = $"egg_{s_uniqueID++}"; Egg egg = objectBase.GetComponent <Egg>(); egg.ObjectID = objID; int r = GlobalRandom.GetRandom(0, 10); Debug.Log($"랜덤 {r}"); bool male = r < 5; egg.male = male; foodsList.Add(objID, egg); eggCount++; return(egg); }
public Idle(Duck duck) : base(duck) { changeStateToMatingCondition = () => { // 일정확률로 발정상태에 빠진다 // 태어난지 5일 이후? 혹은... 마지막 발정 이후 5일 이후 부터 가능 if (owner.LastMatingTime + World.oneDay * 5 <= World.CurrentGameWorldTimeMS) { if (owner.CurrentHeat >= GlobalRandom.GetRandom(1, 100)) { return(true); } } return(false); }; changeStateToMating = () => owner.ChangeState("Mating"); jobConditionForLeftWork = () => World.GetInstance().IsJobEmpty(World.JobType.CarrySomethingStopped) == false; workForSomethingToLeft = () => { JobInfo job = World.GetInstance().GetFirstJob(World.JobType.CarrySomethingStopped); bool isPossible = false; if (job != null) { if (job.targetBuilding is PocketBuilding) { isPossible = job.targetBuilding.GetComponent <PocketBuilding>().AskEnterable(); } else if (job.targetBuilding is IFoodConsumeableBuilding) { isPossible = !job.targetBuilding.GetComponent <IFoodConsumeableBuilding>().FoodIsFull(); } else if (job.targetBuilding is IResourceConsumeableBuilding) { isPossible = !job.targetBuilding.GetComponent <IResourceConsumeableBuilding>().ResourceIsFull(); } if (isPossible) { owner.ChangeState("Carry", new Dictionary <string, ObjectBase>() { { "target", job.targetObject }, { "targetBuilding", job.targetBuilding } }); } else { World.GetInstance().RequestCarrySomethingStopped(job.targetObject, job.targetBuilding); } } }; jobConditionForFishing = () => { if (World.GetInstance().FindMainStorage().GetComponent <IFoodConsumeableBuilding>().FoodIsFull() == false) { return(true); } else { return(false); } }; workForFishing = () => { JobInfo job = World.GetInstance().GetFirstJob(World.JobType.CatchFishingInPond); if (job != null) { owner.ChangeState("Fishing", job.targetBuilding); } }; jobConditionForUserCommand = () => (World.GetInstance().FindEggAtGround() != null); //&&( World.GetInstance().IsJobEmpty(World.JobType.CarryOnEggToHatchery) == false //|| World.GetInstance().IsJobEmpty(World.JobType.CarryOnEggToMainStorage) == false )); workForUserCommand = () => { Egg eggOnGround = World.GetInstance().FindEggAtGround(); if (World.GetInstance().IsJobEmpty(World.JobType.CarryOnEggToHatchery) == false) { // job은 꺼내지 않는다(계속 유지) // 알옮기자, 부화장으로 owner.ChangeState("Carry", new Dictionary <string, ObjectBase>() { { "target", eggOnGround }, { "targetBuilding", World.GetInstance().FindEnterablePocketBuilding(owner, World.BuildingType.hatchery) } }); } else if (World.GetInstance().IsJobEmpty(World.JobType.CarryOnEggToMainStorage) == false) { // 알옮기자, 저장고로 owner.ChangeState("Carry", new Dictionary <string, ObjectBase>() { { "target", eggOnGround }, { "targetBuilding", World.GetInstance().FindMainStorage() } }); } return; }; surviveCondition = () => owner.Hunger >= 60 || owner.Fatigue >= 60; changeStateToSurvive = () => { if (owner.Hunger >= owner.Fatigue) { owner.ChangeState("Eat"); } else { owner.ChangeState("Sleep"); } }; //우선순위 리스트에 다 때려넣어보자 //0순위는 부동 owner.priorityLists.Add(new KeyValuePair <string, KeyValuePair <Func <bool>, Action> >("CarrySomethingStopped", new KeyValuePair <Func <bool>, Action>(jobConditionForLeftWork, workForSomethingToLeft))); owner.priorityLists.Add(new KeyValuePair <string, KeyValuePair <Func <bool>, Action> >("낚시", new KeyValuePair <Func <bool>, Action>(jobConditionForFishing, workForFishing))); owner.priorityLists.Add(new KeyValuePair <string, KeyValuePair <Func <bool>, Action> >("유저의 명령", new KeyValuePair <Func <bool>, Action>(jobConditionForUserCommand, workForUserCommand))); owner.priorityLists.Add(new KeyValuePair <string, KeyValuePair <Func <bool>, Action> >("생존", new KeyValuePair <Func <bool>, Action>(surviveCondition, changeStateToSurvive))); owner.priorityLists.Add(new KeyValuePair <string, KeyValuePair <Func <bool>, Action> >("번식", new KeyValuePair <Func <bool>, Action>(changeStateToMatingCondition, changeStateToMating))); }