Esempio n. 1
0
        public static IEnumerator UpdateFollowGoal(Motile m, MotileAction action)
        {
            action.IsInRange = false;
            if (!m.AvoidingObstacle && action.LiveTarget != null)
            {
                //only update the goal object position if we're not avoiding an obstacle
                m.GoalObject.position = action.LiveTarget.Position;
            }
            float distanceFromTarget = Vector3.Distance(m.worlditem.Position, m.GoalObject.position);

            action.IsInRange = distanceFromTarget < action.Range;
            if (action.IsInRange)
            {
                m.TargetMovementSpeed = m.State.MotileProps.SpeedIdleWalk;
            }
            else
            {
                if (distanceFromTarget <= action.Range * 2.0f || action.WalkingSpeed)
                {
                    m.TargetMovementSpeed = m.State.MotileProps.SpeedWalk;
                }
                else
                {
                    m.TargetMovementSpeed = m.State.MotileProps.SpeedRun;
                }
            }
            //wait a tick
            yield return(null);

            yield break;
        }
Esempio n. 2
0
        public static IEnumerator SendGoalToRandomPosition(Motile m, Vector3 origin, float maxRange, float minRange)
        {
            if (m == null || m.GoalObject == null)
            {
                yield break;
            }

            //Debug.Log (m.name + " Sending goal to random position in " + mRandomPosition.ToString ());
            mRandomDirection = UnityEngine.Random.insideUnitSphere.WithY(0f) * UnityEngine.Random.Range(minRange, maxRange);
            mRandomPosition  = mRandomDirection + origin;
            mRandomTerrainHit.groundedHeight = m.terrainHit.groundedHeight;
            mRandomTerrainHit.overhangHeight = m.terrainHit.overhangHeight;
            mRandomTerrainHit.feetPosition   = mRandomPosition;
            mRandomTerrainHit.ignoreWater    = false;
            mRandomTerrainHit.hitWater       = true;
            //keep trying until we stop hitting water
            while (mRandomTerrainHit.hitWater)
            {
                if (m.worlditem.Group.Props.Interior)
                {
                    //TODO get interior position
                }
                else
                {
                    mRandomPosition.y = GameWorld.Get.TerrainHeightAtInGamePosition(ref mRandomTerrainHit);
                }
                yield return(null);
            }
            if (m != null && m.GoalObject != null)
            {
                m.GoalObject.position = mRandomPosition;
            }
            yield break;
        }
Esempio n. 3
0
        public static IEnumerator UpdateFollowRoutine(Motile m, MotileAction action)
        {
            yield return(null);

            yield break;
            //TODO: Come back and fix this.
        }
Esempio n. 4
0
        public override void OnInitialized()
        {
            if (Profile.Get.CurrentGame.Difficulty.IsDefined("NoHostileCreatures") && worlditem.Is <Creature> ())
            {
                Finish();
                return;
            }
            else if (Profile.Get.CurrentGame.Difficulty.IsDefined("NoHostileCharacters") && worlditem.Is <Character> ())
            {
                Finish();
                return;
            }

            Damageable damageable = worlditem.Get <Damageable> ();

            damageable.OnDie += OnDie;
            mStalkAction      = new MotileAction();
            mWatchAction      = new MotileAction();
            mWarnAction       = new MotileAction();
            motile            = worlditem.Get <Motile> ();
            looker            = worlditem.Get <Looker> ();
            body              = motile.Body;

            if (body == null)
            {
                Finish();
                return;
            }

            RefreshAttackSettings();

            Player.Local.Surroundings.AddHostile(this);
        }
Esempio n. 5
0
        protected IEnumerator StunnedOverTime(double RTDuration)
        {
            //don't think about stuff in the meantime
            enabled = false;
            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                //stop doing stuff in the meantime
                motile.IsRagdoll = true;
            }

            double reviveTime = WorldClock.AdjustedRealTime + RTDuration;

            while (mIsStunned && WorldClock.AdjustedRealTime < reviveTime)
            {
                double waitUntil = Frontiers.WorldClock.AdjustedRealTime + 1f;
                while (Frontiers.WorldClock.AdjustedRealTime < waitUntil)
                {
                    yield return(null);
                }
            }
            //if we're not dead
            if (!IsDead)
            {
                if (motile != null)
                {
                    //start doing stuff again
                    motile.IsRagdoll = false;
                }
                OnRevived.SafeInvoke();
            }
            mIsStunned = false;
            yield break;
        }
Esempio n. 6
0
        protected void OnCharacterEnter(Character character, Motile motile)
        {
            if (State.Users == ActionNodeUsers.SpecifiedOccupantOnly &&
                character.worlditem.FileName != State.OccupantName)
            {
                return;
            }

            //if we're supposed to tell characters to occupy on enter
            //and if we don'
            //and if the character is not the current occupant
            if (State.TryToOccupyOnEnter &&
                !(State.TryToOccupyOnce && State.NumTimesOccupied > 0) &&
                mOccupant != character.worlditem)                                       //make sure we should try to enter first
            //if it's the right character, wuhoo!
            {
                MotileAction newAction = new MotileAction();
                newAction.Type       = MotileActionType.GoToActionNode;
                newAction.Target     = new MobileReference(State.Name, State.ParentGroupPath);
                newAction.LiveTarget = this;
                newAction.Expiration = MotileExpiration.TargetOutOfRange;
                if (State.UseTrigger)                                   //keep the range smaller so we get to the middle
                {
                    newAction.Range = 2.5f;                             //TODO kludge
                }
                else                                                    //use the standard minimum range
                {
                    newAction.Range = mMinimumRadius;
                }
                newAction.OutOfRange = State.TriggerRadius * 2.0f;
                motile.PushMotileAction(newAction, MotileActionPriority.ForceTop);
            }
        }
Esempio n. 7
0
        public void OnPlayerEncounter()
        {
            if (character.IsDead || character.IsStunned || character.IsSleeping)
            {
                return;
            }

            if (State.DTSOnPlayerEncounter && !string.IsNullOrEmpty(State.DTSSpeechName))
            {
                Motile motile = null;
                if (worlditem.Is <Motile> (out motile))                  //get the listener target = use focus object
                //send a motile action to keep the character in place
                //the FocusObject will be moved around by the speech bubble each page
                {
                    if (mSpeechMotileAction == null)
                    {
                        mSpeechMotileAction = new MotileAction();
                    }
                    mSpeechMotileAction.Reset();
                    mSpeechMotileAction.Type          = MotileActionType.FocusOnTarget;
                    mSpeechMotileAction.Expiration    = MotileExpiration.Never;
                    mSpeechMotileAction.YieldBehavior = MotileYieldBehavior.YieldAndFinish;
                    mSpeechMotileAction.IdleAnimation = GameWorld.Get.FlagByName("IdleAnimation", "Talking");
                    mSpeechMotileAction.LiveTarget    = Player.Local;
                    //we want normal because we want to reach the action node first
                    motile.PushMotileAction(mSpeechMotileAction, MotileActionPriority.Next);
                }
                GiveSpeech(State.DTSSpeechName, null);
            }
        }
Esempio n. 8
0
        protected IEnumerator SleepingOverTime(Bed bed)
        {
            //first go to the bed sleep point
            //TODO make this a motile action
            worlditem.tr.position = bed.SleepingPosition;
            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                mSleepAction.Reset();
                mSleepAction.IdleAnimation = GameWorld.Get.FlagByName("IdleAnimation", "Sleeping");
                motile.PushMotileAction(mSleepAction, MotileActionPriority.ForceTop);
                //let them sleep zzzzz
                yield return(mSleepAction.WaitForActionToFinish(0.25f));

                //once we wake up, if the bed is not null
                //clear its occupant!
                if (bed != null)
                {
                    bed.Occupant = null;
                }
            }
            mIsSleeping = false;
            yield break;
        }
Esempio n. 9
0
        public void OnRefreshBehavior( )
        {
            if (!mInitialized)
            {
                return;
            }

            if (creature.State.Domestication != DomesticatedState.Tamed)
            {
                Finish();
                return;
            }

            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                //make the base action to follow whoever we're imprinted on
                //this way it'll be the default thing we do
                //and we won't have to worry about keeping up on it
                mFollowLeaderAction = motile.State.BaseAction;
                mFollowLeaderAction.Reset();
                mFollowLeaderAction.Type         = MotileActionType.FollowTargetHolder;
                mFollowLeaderAction.Expiration   = MotileExpiration.Never;
                mFollowLeaderAction.Range        = 2f;
                mFollowLeaderAction.LiveTarget   = Player.Local;
                mFollowLeaderAction.FollowType   = MotileFollowType.Companion;
                mFollowLeaderAction.Instructions = MotileInstructions.CompanionInstructions;
            }
        }
Esempio n. 10
0
        public void ActivateGhost()
        {
            if (mActivating | mDeactivating)
            {
                return;
            }

            Activated = true;

            if (mSpeakingCharacter == null || mSpeakingCharacter.IsDestroyed)
            {
                if (mCharacterSpawnPoint == null)
                {
                    WorldChunk      c = worlditem.Group.GetParentChunk();
                    ActionNodeState actionNodeState = null;
                    string          nodeName        = worlditem.FileName + "GhostNode";
                    if (!c.GetOrCreateNode(worlditem.Group, worlditem.tr, worlditem.FileName + "GhostNode", out actionNodeState))
                    {
                        Debug.LogError("Couldn't create spawn node " + nodeName + " in ghost to create character");
                        return;
                    }
                    actionNodeState.actionNode.transform.position = worlditem.tr.position;
                    actionNodeState.CustomConversation            = State.CharacterConversation;
                    if (!Characters.GetOrSpawnCharacter(actionNodeState.actionNode, State.CharacterName, worlditem.Group, out mSpeakingCharacter))
                    {
                        Debug.LogError("Couldn't spawn character " + State.CharacterName + " in ghost");
                    }
                    else
                    {
                        mSpeakingCharacter.worlditem.ActiveState       = WIActiveState.Visible;
                        mSpeakingCharacter.worlditem.ActiveStateLocked = true;
                        Debug.Log("Setting character's conversation name to " + State.CharacterConversation);
                        //we don't need motile for this character
                        Motile m = null;
                        if (mSpeakingCharacter.worlditem.Is <Motile> (out m))
                        {
                            m.Finish();
                        }
                        mSpeakingCharacter.Ghost = true;
                        mSpeakingCharacter.Body.OnSpawn(mSpeakingCharacter);
                    }
                }
            }

            if (mSpeakingCharacter != null)
            {
                Talkative t = mSpeakingCharacter.worlditem.Get <Talkative> ();
                t.State.ConversationName = State.CharacterConversation;
                t.State.DefaultToDTS     = false;
                //don't show the body until we're sure it has its materials
                mSpeakingCharacter.Body.SetVisible(false);
                mSpeakingCharacter.Body.IgnoreCollisions(true);
                mSpeakingCharacter.Body.LockVisible = true;
                mActivating = true;
                StartCoroutine(ActivateOverTime());
                enabled = true;
            }
        }
Esempio n. 11
0
        public static bool UpdateExpiration(Motile m, MotileAction action)
        {
            if (action.BaseAction)
            {
                return(false);
            }

            bool expire = false;

            switch (action.Expiration)
            {
            case MotileExpiration.Duration:
                double expireTime = action.WTStarted + action.RTDuration;
                expire = WorldClock.AdjustedRealTime > expireTime;
                break;

            case MotileExpiration.TargetInRange:
                if (action.HasLiveTarget)                       //are we close enough to our target?
                {
                    expire = (Vector3.Distance(action.LiveTarget.Position, m.LastKnownPosition) < action.Range);
                }
                else
                {
                    expire = (Vector3.Distance(m.GoalObject.position, m.LastKnownPosition) < action.Range);
                }
                //if no live target get non-live target and measure (?)
                break;

            case MotileExpiration.TargetOutOfRange:
                if (action.HasLiveTarget)                       //are we too far from our target?
                {
                    expire = (Vector3.Distance(action.LiveTarget.Position, m.LastKnownPosition) > action.OutOfRange);
                }
                else
                {
                    expire = (Vector3.Distance(m.GoalObject.position, m.LastKnownPosition) > action.OutOfRange);
                }
                //if no live target get non-live target and measure (?)
                break;

            case MotileExpiration.Never:
            default:
                break;
            }
                        #if UNITY_EDITOR
            if (expire)
            {
                //Debug.Log ("action " + action.Name + " expired because " + action.Expiration.ToString ());
            }
                        #endif
            return(expire);
        }
Esempio n. 12
0
 public static void SendGoalAwayFromObstacle(Motile m, Vector3 origin, float maxRange, float minRange, Bounds mObstacleBounds)
 {
     mRandomPosition = m.LastKnownPosition + (UnityEngine.Random.onUnitSphere.WithY(0f) * UnityEngine.Random.Range(minRange, maxRange));
     if (m.worlditem.Group.Props.Interior)
     {
         //TODO get interior position
     }
     else
     {
         mRandomPosition.y = GameWorld.Get.TerrainHeightAtInGamePosition(ref mRandomTerrainHit);
     }
     m.GoalObject.position = mRandomPosition;
 }
Esempio n. 13
0
        public override void OnInitialized()
        {
            CheckTemplate();

            worlditem.OnActive          += OnActive;
            worlditem.OnVisible         += OnVisible;
            worlditem.OnInactive        += OnInactive;
            worlditem.OnPlayerEncounter += OnPlayerEncounter;
            worlditem.OnAddedToGroup    += OnAddedToGroup;

            photosensitive = worlditem.GetOrAdd <Photosensitive> ();
            photosensitive.OnExposureDecrease += RefreshEyes;
            photosensitive.OnExposureDecrease += RefreshEyes;

            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                motile.SetBody(Body);
                //always set the motile props even if we've saved the state
                motile.State.MotileProps = Template.MotileTemplate.MotileProps;
            }
            Looker looker = null;

            if (worlditem.Is <Looker> (out looker))
            {
                looker.OnSeeItemOfInterest += OnSeeItemOfInterest;
            }
            Listener listener = null;

            if (worlditem.Is <Listener> (out listener))
            {
                listener.OnHearItemOfInterest += OnHearItemOfInterest;
            }
            damageable = worlditem.Get <Damageable> ();
            damageable.OnTakeDamage         += OnTakeDamage;
            damageable.OnTakeCriticalDamage += OnTakeCriticalDamage;
            damageable.OnTakeOverkillDamage += OnTakeOverkillDamage;
            damageable.OnDie += OnDie;

            Container container = worlditem.Get <Container> ();

            container.CanOpen      = false;
            container.CanUseToOpen = false;

            OnDaytimeStart   += RefreshBehavior;
            OnNightTimeStart += RefreshBehavior;
            OnHourStart      += RefreshBehavior;

            //WanderAction ();
        }
Esempio n. 14
0
        protected IEnumerator SayDTSOverTime()
        {
            //spawn an effect over the characters' head
            Motile motile = worlditem.Get <Motile> ();

            FXManager.Get.SpawnFX(motile.Body.Transforms.HeadTop.gameObject, "SpeakEffect", Vector3.zero);

            mSayingDTS   = true;
            mLastDTSPage = -1;
            string pageText     = string.Empty;
            float  pageDuration = 0.0f;
            bool   continueDTS  = true;

            if (!string.IsNullOrEmpty(mDTS.OnFinishCommand))
            {
                mSpeechBubble = CreateSpeechBubble(mDTS, null, worlditem.tr);
            }
            yield return(null);

            while (continueDTS)
            {
                continueDTS = mDTS.GetPage(ref pageText, ref pageDuration, ref mLastDTSPage, true);
                if (continueDTS)
                {
                    NGUIScreenDialog.AddSpeech(pageText, worlditem.DisplayName, pageDuration);
                    double waitUntil = Frontiers.WorldClock.AdjustedRealTime + pageDuration;
                    while (Frontiers.WorldClock.AdjustedRealTime < waitUntil)
                    {
                        yield return(null);
                    }
                }
            }
            if (mSpeechBubble != null)
            {
                mSpeechBubble.FinishSpeech();
            }
            if (!string.IsNullOrEmpty(mDTS.OnFinishMissionActivate))
            {
                if (!string.IsNullOrEmpty(mDTS.OnFinishObjectiveActivate))
                {
                    Missions.Get.ActivateObjective(mDTS.OnFinishMissionActivate, mDTS.OnFinishObjectiveActivate, MissionOriginType.Character, worlditem.FileName);
                }
                else
                {
                    Missions.Get.ActivateMission(mDTS.OnFinishMissionActivate, MissionOriginType.Character, worlditem.FileName);
                }
            }
            mDTS       = null;
            mSayingDTS = false;
            yield break;
        }
Esempio n. 15
0
        protected IEnumerator StartSpeech(DispatchedSpeech speech)
        {
            if (speech.speech == null)
            {
                Debug.Log("Speech is null, breaking");
            }

            State.LastSpeechName    = speech.speech.Name;
            State.LastSpeechStarted = WorldClock.AdjustedRealTime;
            State.LastSpeechPage    = -1;

            speech.speech.StartSpeech(worlditem.FileName);
            Mods.Get.Runtime.SaveMod <Speech> (speech.speech, "Speech", speech.speech.Name);
            //send motile action
            Transform listenerTarget = null;
            Motile    motile         = null;

            Debug.Log("Giving speech over time in character...");
            if (worlditem.Is <Motile> (out motile))              //get the listener target = use focus object
            {
                listenerTarget = motile.GoalObject;
                //send a motile action to keep the character in place
                //the FocusObject will be moved around by the speech bubble each page
                if (mSpeechMotileAction == null)
                {
                    mSpeechMotileAction = new MotileAction();
                }
                mSpeechMotileAction.Reset();
                mSpeechMotileAction.Type       = MotileActionType.FocusOnTarget;
                mSpeechMotileAction.Expiration = MotileExpiration.Never;
                if (speech.speech.CanBeInterrupted)                     //if we can be interrupted, let the speech cut off
                {
                    mSpeechMotileAction.YieldBehavior = MotileYieldBehavior.YieldAndFinish;
                }
                else                            //if it can't be interrupted, do not yield to other actions
                {
                    mSpeechMotileAction.YieldBehavior = MotileYieldBehavior.DoNotYield;
                }
                mSpeechMotileAction.IdleAnimation = GameWorld.Get.FlagByName("IdleAnimation", "Talking");
                //we want normal because we want to reach the action node first
                motile.PushMotileAction(mSpeechMotileAction, MotileActionPriority.Next);
            }
            else
            {
                listenerTarget = worlditem.tr;
            }

            //create speech bubble
            mSpeechBubble = CreateSpeechBubble(speech.speech, speech.dispatcher, listenerTarget);
            yield break;
        }
Esempio n. 16
0
        public override void OnInitialized()
        {
            creature = worlditem.Get <Creature> ();
            creature.OnCollectiveThoughtStart += OnCollectiveThoughtStart;
            creature.OnRevived += OnRevived;
            creature.Template.Props.CanOpenContainerOnDie = false;

            Looker looker = worlditem.Get <Looker> ();

            looker.State.ItemsOfInterest.Clear();
            looker.State.ItemsOfInterest.AddRange(ThingsOrbsFindInteresting);

            motile = worlditem.Get <Motile> ();

            OrbExplosionDamage.DamageSent      = 15f;
            OrbExplosionDamage.ForceSent       = 0.75f;
            OrbExplosionDamage.MaterialBonus   = WIMaterialType.Flesh;
            OrbExplosionDamage.MaterialPenalty = WIMaterialType.Metal;

            damageable = worlditem.Get <Damageable> ();
            damageable.State.Result = DamageableResult.Die;
            damageable.OnDie       += OnDie;

            DropItems                         = worlditem.GetOrAdd <DropItemsOnDie> ();
            DropItems.DropEffect              = "DrawAttentionToItem";
            DropItems.DropForce               = 0.05f;
            DropItems.WICategoryName          = creature.Template.Props.InventoryFillCategory;
            DropItems.RandomDropout           = 0f;
            DropItems.DropEveryItemInCategory = true;

            PowerSource = worlditem.GetOrAdd <LuminitePowered> ();

            worlditem.OnScriptAdded += OnScriptAdded;

            Meteors.Get.OnMeteorSpawned += OnMeteorSpawned;

            if (!mUpdatingBehavior)
            {
                mUpdatingBehavior = true;
                StartCoroutine(UpdateBehavior());
            }

            MeteorSearchRange = creature.Den.Radius;

            BehaviorState = OrbBehaviorState.Awakening;

            //orbs never become inactive
            worlditem.ActiveState       = WIActiveState.Active;
            worlditem.ActiveStateLocked = true;
        }
Esempio n. 17
0
        public void OnInactive()
        {
            if (IsDead)
            {
                return;
            }

            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                motile.StartMotileActions();
            }
        }
Esempio n. 18
0
        public void OnPlayerEncounter()
        {
            if (IsDead)
            {
                return;
            }

            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                motile.StartMotileActions();
            }
        }
Esempio n. 19
0
        public void OnGainPlayerFocus()
        {
            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                motile.StartMotileActions();
            }
            if (State.BroadcastFocus)
            {
                Player.Get.AvatarActions.ReceiveAction(AvatarAction.NpcFocus, WorldClock.AdjustedRealTime);
            }
            enabled = true;
        }
Esempio n. 20
0
        public static IEnumerator UpdateWanderIdly(Motile m, MotileAction action)
        {
            //m.rvoController.PositionLocked = false;
            //m.rvoController.RotationLocked = false;
            m.TargetMovementSpeed = m.State.MotileProps.SpeedIdleWalk;
            IEnumerator sendGoal = null;

            if (m.HasReachedGoal(m.State.MotileProps.RVORadius))
            {
                if (UnityEngine.Random.value < (m.State.MotileProps.IdleWanderThreshold / 100))
                {
                    //choose a new direction no matter what
                    switch (action.TerritoryType)
                    {
                    case MotileTerritoryType.Den:
                        sendGoal = SendGoalToRandomPosition(m, action.TerritoryBase.Position, action.TerritoryBase.Radius, action.TerritoryBase.InnerRadius);
                        while (sendGoal.MoveNext())
                        {
                            yield return(sendGoal.Current);
                        }
                        break;

                    case MotileTerritoryType.None:
                    default:
                        sendGoal = SendGoalToRandomPosition(m, m.GoalObject.position, action.Range, action.Range / 2f);
                        while (sendGoal.MoveNext())
                        {
                            yield return(sendGoal.Current);
                        }
                        break;
                    }
                }
            }
            else if (!m.AvoidingObstacle && UnityEngine.Random.value < (m.State.MotileProps.IdleWaitThreshold / 100))
            {
                sendGoal = SendGoalToRandomPosition(m, m.worlditem.Position, action.Range, 0.5f);                 //this will make us look around
                while (sendGoal.MoveNext())
                {
                    yield return(sendGoal.Current);
                }
            }
            double finishTime = WorldClock.AdjustedRealTime + 0.25f;

            while (WorldClock.AdjustedRealTime < finishTime)
            {
                yield return(null);
            }
            yield break;
        }
Esempio n. 21
0
        public MotileAction WatchThingAction(IItemOfInterest itemOfInterest)
        {
            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                if (mFocusAction.IsFinished || mFocusAction.LiveTarget != itemOfInterest)
                {
                    mFocusAction.Reset();
                    mFocusAction.LiveTarget = itemOfInterest;
                    motile.PushMotileAction(mFocusAction, MotileActionPriority.ForceTop);
                }
            }
            return(mFocusAction);
        }
Esempio n. 22
0
        public MotileAction FollowThingAction(IItemOfInterest itemOfInterest)
        {
            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                if (mFollowAction.State == MotileActionState.NotStarted || mFollowAction.IsFinished || mFollowAction.LiveTarget != itemOfInterest)
                {
                    mFollowAction.Reset();
                    mFollowAction.LiveTarget = itemOfInterest;
                    motile.PushMotileAction(mFollowAction, MotileActionPriority.ForceTop);
                }
            }
            return(mFollowAction);
        }
Esempio n. 23
0
        public override void OnInitializedFirstTime()
        {
            CheckTemplate();
            //set the states of our looker, listener, motile etc. using our template
            //this will only happen the first time the creature is created
            //after that it will pull this info from its stack item state
            Looker looker = null;

            if (worlditem.Is <Looker> (out looker))
            {
                Reflection.CopyProperties(Template.LookerTemplate, looker.State);
            }
            Listener listener = null;

            if (worlditem.Is <Listener> (out listener))
            {
                Reflection.CopyProperties(Template.ListenerTemplate, listener.State);
            }
            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                Reflection.CopyProperties(Template.MotileTemplate, motile.State);
            }
            FillStackContainer fsc = null;

            if (worlditem.Is <FillStackContainer> (out fsc))
            {
                if (string.IsNullOrEmpty(Template.Props.InventoryFillCategory))
                {
                    Template.Props.InventoryFillCategory = Creatures.Get.DefaultInventoryFillCategory;
                }
                fsc.State.WICategoryName = Template.Props.InventoryFillCategory;
            }
            //all creatures are damageable
            damageable = worlditem.Get <Damageable> ();
            damageable.ApplyForceAutomatically = false;
            if (!State.IsDead)
            {
                Reflection.CopyProperties(Template.DamageableTemplate, damageable.State);
            }
            //add each of the custom scripts in the template
            for (int i = 0; i < Template.Props.CustomWIScripts.Count; i++)
            {
                worlditem.Add(Template.Props.CustomWIScripts [i]);
            }
            //and we're done!
        }
Esempio n. 24
0
        public static bool GetUpdateCoroutine(Motile m, MotileAction action)
        {
            if (action.TerritoryType == MotileTerritoryType.Den &&
                !Physics.CheckSphere(m.LastKnownPosition, action.TerritoryBase.Radius))
            {
                //we've exceeded our territory bounds
                //return to our territory
                action.UpdateCoroutine = UpdateReturnToTerritoryBase(m, action);
                return(true);
            }

            switch (action.Type)
            {
            case MotileActionType.FocusOnTarget:
                action.UpdateCoroutine = UpdateFocusOnTarget(m, action);
                break;

            case MotileActionType.FollowRoutine:
                action.UpdateCoroutine = UpdateFollowRoutine(m, action);
                break;

            case MotileActionType.FollowGoal:
                action.UpdateCoroutine = UpdateFollowGoal(m, action);
                break;

            case MotileActionType.FleeGoal:
                action.UpdateCoroutine = UpdateFleeGoal(m, action);
                break;

            case MotileActionType.WanderIdly:
                action.UpdateCoroutine = UpdateWanderIdly(m, action);
                break;

            case MotileActionType.FollowTargetHolder:
                action.UpdateCoroutine = UpdateFollowTargetHolder(m, action);
                break;

            case MotileActionType.GoToActionNode:
                action.UpdateCoroutine = UpdateGoToActionNode(m, action);
                break;

            case MotileActionType.Wait:
            default:
                action.UpdateCoroutine = UpdateWait(m, action);
                break;
            }
            return(action.UpdateCoroutine != null);
        }
Esempio n. 25
0
        public MotileAction FollowThingAction(IItemOfInterest itemOfInterest)
        {
            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                if (mFollowAction.IsFinished || mFollowAction.LiveTarget != itemOfInterest)
                {
                    mFollowAction.Reset();
                    mFollowAction.LiveTarget    = itemOfInterest;
                    mFollowAction.TerritoryBase = TerritoryBase;                    //null typically
                    motile.PushMotileAction(mFollowAction, MotileActionPriority.ForceTop);
                }
            }
            return(mFollowAction);
        }
Esempio n. 26
0
        public MotileAction GoToThing(IItemOfInterest itemOfInterest)
        {
            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                if (mPursueGoalAction.IsFinished || mPursueGoalAction.LiveTarget != itemOfInterest || itemOfInterest == null)
                {
                    mPursueGoalAction.Reset();
                    mPursueGoalAction.LiveTarget    = itemOfInterest;
                    mPursueGoalAction.TerritoryBase = TerritoryBase;                    //null typically
                    motile.PushMotileAction(mPursueGoalAction, MotileActionPriority.ForceTop);
                }
            }
            return(mPursueGoalAction);
        }
Esempio n. 27
0
        public void OnAddedToGroup()
        {
            CurrentThought.OnFleeFromIt += FleeFromThing;
            CurrentThought.OnKillIt     += AttackThing;
            CurrentThought.OnEatIt      += WatchThing;       //TODO fix this
            CurrentThought.OnFollowIt   += FollowThing;
            CurrentThought.OnWatchIt    += WatchThing;

            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                motile.StartMotileActions();
            }
            Characters.Get.BodyTexturesAndMaterials(this, Ghost);
        }
Esempio n. 28
0
        public MotileAction WatchThingAction(IItemOfInterest itemOfInterest)
        {
            //if the creature is idle, turn to look at the player
            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                if (mFocusAction.State == MotileActionState.NotStarted || mFocusAction.IsFinished || mFocusAction.LiveTarget != itemOfInterest)
                {
                    mFocusAction.Reset();
                    mFocusAction.LiveTarget = itemOfInterest;
                    motile.PushMotileAction(mFocusAction, MotileActionPriority.ForceTop);
                }
            }
            return(mFocusAction);
        }
Esempio n. 29
0
        public MotileAction FleeFromThingAction(IItemOfInterest itemOfInterest)
        {
            Body.EyeMode = BodyEyeMode.Timid;
            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                if (mFleeThreatAction.State == MotileActionState.NotStarted || mFleeThreatAction.IsFinished || mFleeThreatAction.LiveTarget != itemOfInterest)
                {
                    mFleeThreatAction.Reset();
                    mFleeThreatAction.LiveTarget    = itemOfInterest;
                    mFleeThreatAction.YieldBehavior = MotileYieldBehavior.DoNotYield;
                    motile.PushMotileAction(mFleeThreatAction, MotileActionPriority.ForceTop);
                }
            }
            return(mFleeThreatAction);
        }
Esempio n. 30
0
        public MotileAction ReturnToDenInnerRadius()
        {
            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                if (mReturnToDenAction.IsFinished)
                {
                    mReturnToDenAction.Reset();
                    mReturnToDenAction.Expiration    = MotileExpiration.TargetInRange;
                    mReturnToDenAction.Range         = Den.InnerRadius;
                    mReturnToDenAction.YieldBehavior = MotileYieldBehavior.DoNotYield;
                    motile.PushMotileAction(mReturnToDenAction, MotileActionPriority.ForceTop);
                }
            }
            return(mReturnToDenAction);
        }