Exemplo n.º 1
0
            public override void InitializeStates(out BaseState defaultState)
            {
                serializable = true;
                defaultState = Alive;

                var plantname = CREATURES.STATUSITEMS.DEAD.NAME;
                var tooltip   = CREATURES.STATUSITEMS.DEAD.TOOLTIP;
                var main      = Db.Get().StatusItemCategories.Main;

                Dead
                .ToggleStatusItem(plantname, tooltip, string.Empty, StatusItem.IconType.Info, 0, false, OverlayModes.None.ID, 0, null, null, main)
                .Enter(smi =>
                {
                    if (!UprootedMonitor.IsObjectUprooted(masterTarget.Get(smi)))
                    {
                        smi.master.gameObject.AddOrGet <Notifier>().Add(smi.master.CreateDeathNotification(), string.Empty);
                    }

                    GameUtil.KInstantiate(Assets.GetPrefab(EffectConfigs.PlantDeathId), smi.master.transform.GetPosition(),
                                          Grid.SceneLayer.FXFront).SetActive(true);
                    smi.master.Trigger((int)GameHashes.Died);
                    smi.master.GetComponent <KBatchedAnimController>().StopAndClear();
                    Destroy(smi.master.GetComponent <KBatchedAnimController>());
                    smi.Schedule(0.5f, smi.master.DestroySelf);
                });

                Alive
                .InitializeStates(masterTarget, Dead)
                .DefaultState(Alive.Closed);

                Alive.Closed
                .PlayAnim("close")
                .Update("closed", (smi, dt) =>
                {
                    AbsorbHeat(smi, dt);

                    if (smi.master._kjConsumed > smi.master._openEnergyThreshold)
                    {
                        smi.GoTo(Alive.Open);
                    }
                }, UpdateRate.SIM_1000ms);

                Alive.Open.PlayAnim("open", KAnim.PlayMode.Once)
                .Enter(smi => smi.master._lightSource.enabled = true)
                .Update("open", (smi, dt) =>
                {
                    AbsorbHeat(smi, dt);

                    smi.master._kjConsumed -= smi.master._lightKjConsumptionRate;

                    if (smi.master._kjConsumed < smi.master._lightKjConsumptionRate)
                    {
                        smi.GoTo(Alive.Closed);
                    }
                }, UpdateRate.SIM_1000ms)
                .Exit(smi => smi.master._lightSource.enabled = false);
            }
Exemplo n.º 2
0
            public override void InitializeStates(out BaseState default_state)
            {
                serializable  = true;
                default_state = alive;

                string             plantname = CREATURES.STATUSITEMS.DEAD.NAME;
                string             tooltip   = CREATURES.STATUSITEMS.DEAD.TOOLTIP;
                StatusItemCategory main      = Db.Get().StatusItemCategories.Main;

                dead.ToggleStatusItem(plantname, tooltip, string.Empty, StatusItem.IconType.Info, 0, false, SimViewMode.None, 0, null,
                                      null, main)
                .Enter(smi =>
                {
                    if (smi.master.growing.Replanted && !UprootedMonitor.IsObjectUprooted(masterTarget.Get(smi)))
                    {
                        smi.master.gameObject.AddOrGet <Notifier>().Add(smi.master.CreateDeathNotification(), string.Empty);
                    }

                    GameUtil.KInstantiate(Assets.GetPrefab(EffectConfigs.PlantDeathId), smi.master.transform.GetPosition(),
                                          Grid.SceneLayer.FXFront).SetActive(true);
                    smi.master.Trigger((int)GameHashes.Died);
                    smi.master.GetComponent <KBatchedAnimController>().StopAndClear();
                    Destroy(smi.master.GetComponent <KBatchedAnimController>());
                    smi.Schedule(0.5f, smi.master.DestroySelf);
                });

                alive
                .InitializeStates(masterTarget, dead)
                .DefaultState(alive.seed_grow).ToggleComponent <Growing>();

                alive.seed_grow
                .QueueAnim("seed_grow")
                .OnAnimQueueComplete(alive.idle);

                alive.idle
                .Enter(smi => smi.master.elementConsumer.EnableConsumption(true))
                .EventTransition(GameHashes.Wilt, alive.wilting_pre, smi => smi.master.wiltCondition.IsWilting())
                .EventTransition(GameHashes.Grow, alive.pre_fruiting, smi => smi.master.growing.ReachedNextHarvest())
                .PlayAnim("idle_loop", KAnim.PlayMode.Loop)
                .Exit(smi => smi.master.elementConsumer.EnableConsumption(false));

                alive.pre_fruiting
                .PlayAnim("grow", KAnim.PlayMode.Once)
                .EventTransition(GameHashes.AnimQueueComplete, alive.fruiting);

                alive.fruiting_lost
                .Enter(smi => smi.master.harvestable.SetCanBeHarvested(false))
                .GoTo(alive.idle);

                alive.wilting_pre
                .QueueAnim("wilt_pre")
                .OnAnimQueueComplete(alive.wilting);

                alive.wilting
                .PlayAnim("idle_wilt_loop", KAnim.PlayMode.Loop)
                .EventTransition(GameHashes.WiltRecover, alive.idle, smi => !smi.master.wiltCondition.IsWilting())
                .EventTransition(GameHashes.Harvest, alive.harvest);


                alive.fruiting
                .DefaultState(alive.fruiting.fruiting_idle)
                .EventTransition(GameHashes.Wilt, alive.wilting_pre)
                .EventTransition(GameHashes.Harvest, alive.harvest)
                .EventTransition(GameHashes.Grow, alive.fruiting_lost, smi => !smi.master.growing.ReachedNextHarvest());

                alive.fruiting.fruiting_idle.PlayAnim("idle_bloom_loop", KAnim.PlayMode.Loop)
                .Enter(smi => smi.master.harvestable.SetCanBeHarvested(true))
                .Enter(smi => smi.master.elementConsumer.EnableConsumption(true))
                .Enter(smi => smi.master.elementEmitter.SetEmitting(true))
                .Update("fruiting_idle", (smi, dt) =>
                {
                    if (!smi.IsOld())
                    {
                        return;
                    }
                    smi.GoTo(alive.fruiting.fruiting_old);
                }, UpdateRate.SIM_4000ms)
                .Exit(smi => smi.master.elementEmitter.SetEmitting(false))
                .Exit(smi => smi.master.elementConsumer.EnableConsumption(false));

                alive.fruiting.fruiting_old
                .PlayAnim("wilt", KAnim.PlayMode.Loop)
                .Enter(smi => smi.master.harvestable.SetCanBeHarvested(true))
                .Update("fruiting_old", (smi, dt) =>
                {
                    if (smi.IsOld())
                    {
                        return;
                    }
                    smi.GoTo(alive.fruiting.fruiting_idle);
                }, UpdateRate.SIM_4000ms);

                alive.harvest
                .PlayAnim("harvest", KAnim.PlayMode.Once)
                .Enter(smi =>
                {
                    if (GameScheduler.Instance != null && smi.master != null)
                    {
                        GameScheduler.Instance.Schedule("SpawnFruit", 0.2f, smi.master.crop.SpawnFruit);
                    }
                    smi.master.harvestable.SetCanBeHarvested(false);
                })
                .OnAnimQueueComplete(alive.idle);
            }