Пример #1
0
        public bool CanSeeItemOfInterest(IItemOfInterest itemOfInterest, bool requireFieldOfView)
        {
            //if it's a visible item
            //we'll want to access its visibility modifiers
            IVisible mVisibleItemCheck = (IVisible)itemOfInterest;

            if (mVisibleItemCheck != null)
            {
                return(CanSeeVisibleItem(mVisibleItemCheck, requireFieldOfView));
            }

            //otherwise we'll just check the item without multipliers
            //we calculate this every time because it could change due to external modifiers
            float mAwarenessDistance = Looker.AwarenessDistanceTypeToVisibleDistance(State.AwarenessDistance);

            if (State.ManualAwarenessDistance > 0)
            {
                mAwarenessDistance = State.ManualAwarenessDistance;
            }

            if (Looker.IsInVisibleRange(worlditem.Position, itemOfInterest.Position, mAwarenessDistance))
            {
                if (!requireFieldOfView || Looker.IsInFieldOfView(worlditem.tr.forward, worlditem.Position, State.FieldOfView, itemOfInterest.Position))
                {
                    //it's in our field of view AND it's close enough to see
                    //check to see if we can see it with the visible item's modifiers in place
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        public void FixedUpdate()
        {
            if (SpawnedBandits.Count == 0)
            {
                enabled = false;
            }

            mLookerCounter++;
            if (mLookerCounter > 2)
            {
                mLookerCounter = 0;
                if (SpawnedBandits.Count > 0)
                {
                    Looker looker = null;
                    if (SharedLooker == null)
                    {
                        CreateSharedLooker();
                    }
                    if (!SharedLooker.IsInUse)
                    {
                        //if the looker is disabled that means it's done being used
                        mUpdateBanditIndex = SpawnedBandits.NextIndex(mUpdateBanditIndex);
                        if (SpawnedBandits [mUpdateBanditIndex] != null)
                        {
                            looker = SpawnedBandits [mUpdateBanditIndex].worlditem.GetOrAdd <Looker> ();
                            //listener is passive but looker is active
                            //it needs to be told to look for the player
                            //we stagger this because it's an expensive operation
                            looker.LookForStuff(SharedLooker);
                        }
                    }
                }
            }
        }
Пример #3
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);
        }
Пример #4
0
        public override void OnInitialized()
        {
            character = worlditem.Get <Character>();
            character.OnCollectiveThoughtStart += OnCollectiveThoughtStart;

            //this script won't get added by default
            looker = worlditem.GetOrAdd <Looker>();
        }
Пример #5
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 ();
        }
Пример #6
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;
        }
Пример #7
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!
        }
Пример #8
0
        public void OnScriptAdded()
        {
            //this may be added by other scripts (eg Student, Bandit)
            Looker looker = null;

            if (worlditem.Is <Looker> (out looker))
            {
                //TODO should we change this?
                Reflection.CopyProperties(Characters.Get.DefaultLookerState, looker.State);
                //looker.State = ObjectClone.Clone <LookerState>(Characters.Get.DefaultLookerState);
                looker.OnSeeItemOfInterest += OnSeeItemOfInterest;
            }
            Listener listener = null;

            if (worlditem.Is <Listener> (out listener))
            {
                Reflection.CopyProperties(Template.ListenerTemplate, listener.State);
                //listener.State = ObjectClone.Clone <ListenerState>(Template.ListenerTemplate);
                listener.OnHearItemOfInterest += OnHearItemOfInterest;
            }
        }
Пример #9
0
        public override void OnInitializedFirstTime()
        {
            //set the states of our looker & listener using our template
            //this will only happen the first time the character 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);
                //looker.State = ObjectClone.Clone <LookerState>(Template.LookerTemplate);
            }
            Listener listener = null;

            if (worlditem.Is <Listener> (out listener))
            {
                Reflection.CopyProperties(Template.ListenerTemplate, listener.State);
                //listener.State = ObjectClone.Clone <ListenerState>(Template.ListenerTemplate);
            }
            //and we're done!
        }
Пример #10
0
        public bool CanSeeVisibleItem(IVisible visibleItem, bool requireFieldOfView)
        {
            //we calculate this every time because it could change due to external modifiers
            mAwarenessDistance = Looker.AwarenessDistanceTypeToVisibleDistance(State.AwarenessDistance);
            if (State.ManualAwarenessDistance > 0)
            {
                mAwarenessDistance = State.ManualAwarenessDistance;
            }

            if (Looker.IsInVisibleRange(worlditem.Position, visibleItem.Position, mAwarenessDistance) &&
                (!requireFieldOfView || Looker.IsInFieldOfView(worlditem.tr.forward, worlditem.Position, State.FieldOfView, visibleItem.Position)))
            {
                //it's in our field of view AND it's close enough to see
                //check to see if we can see it with the visible item's modifiers in place
                if (visibleItem.IsVisible && Looker.IsInVisibleRange(worlditem.Position, visibleItem.Position, mAwarenessDistance * visibleItem.AwarenessDistanceMultiplier) &&
                    (!requireFieldOfView || Looker.IsInFieldOfView(worlditem.tr.forward, worlditem.Position, State.FieldOfView * visibleItem.FieldOfViewMultiplier, visibleItem.Position)))
                {
                    return(true);
                }
            }

            visibleItem.LookerFailToSee();
            return(false);
        }
Пример #11
0
        public void FixedUpdate()
        {
            if (Globals.MissionDevelopmentMode)
            {
                //we don't care about creatures in mission testing mode
                return;
            }

            if (SpawnedCreatures.Count == 0)
            {
                enabled = false;
            }
            //TODO look into making this a coroutine
            mLookerCounter++;
            if (mLookerCounter > 2)
            {
                mLookerCounter = 0;
                if (SpawnedCreatures.Count > 0)
                {
                    Looker looker = null;
                    if (SharedLooker == null)
                    {
                        CreateSharedLooker();
                    }
                    if (!SharedLooker.IsInUse)
                    {
                        //if the looker is disabled that means it's done being used
                        mUpdateCreatureIndex = SpawnedCreatures.NextIndex(mUpdateCreatureIndex);
                        if (SpawnedCreatures[mUpdateCreatureIndex] != null && SpawnedCreatures[mUpdateCreatureIndex].worlditem.Is <Looker>(out looker))
                        {
                            //listener is passive but looker is active
                            //it needs to be told to look for the player
                            //we stagger this because it's an expensive operation
                            looker.LookForStuff(SharedLooker);
                        }
                    }
                }
            }

            mDenCounter++;
            if (mDenCounter > 3)
            {
                mDenCounter = 0;
                for (int i = 0; i < SpawnedCreatures.Count; i++)
                {
                    if (SpawnedCreatures[i] != null)
                    {
                        if (Vector3.Distance(SpawnedCreatures[i].worlditem.tr.position, worlditem.tr.position) > Radius)
                        {
                            SpawnedCreatures[i].IsInDen = false;
                        }
                        else
                        {
                            SpawnedCreatures[i].IsInDen = true;
                        }
                    }
                }
            }

            mPlayerCounter++;
            if (mPlayerCounter > 4)
            {
                //only when script is enabled
                //only when player is in den
                if (PlayerIsInDen)
                {
                    //go through each creature in our list
                    //tell it to look for the player
                    //now check if the player has entered the den inner radius
                    float distanceToDen = Vector3.Distance(Player.Local.Position, worlditem.tr.position);
                    if (mPlayerVisitingDenInnerRadius)
                    {
                        if (distanceToDen > InnerRadius)
                        {
                            //the player has exited the inner radius
                            //tell each creature
                            mPlayerVisitingDenInnerRadius = false;
                            for (int i = SpawnedCreatures.LastIndex(); i >= 0; i--)
                            {
                                if (SpawnedCreatures[i] == null)
                                {
                                    SpawnedCreatures.RemoveAt(i);
                                }
                                else
                                {
                                    SpawnedCreatures[i].OnPlayerLeaveDenInnerRadius.SafeInvoke();
                                }
                            }
                        }
                    }
                    else
                    {
                        if (distanceToDen < InnerRadius)
                        {
                            //the player has entered the inner radius
                            //tell each creature
                            mPlayerVisitingDenInnerRadius = true;
                            for (int i = SpawnedCreatures.LastIndex(); i >= 0; i--)
                            {
                                if (SpawnedCreatures[i] == null)
                                {
                                    SpawnedCreatures.RemoveAt(i);
                                }
                                else
                                {
                                    SpawnedCreatures[i].OnPlayerVisitDenInnerRadius.SafeInvoke();
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #12
0
        public void OnSeeItemOfInterest()
        {
            Looker looker = worlditem.Get <Looker> ();

            ThinkAboutItemOfInterest(looker.LastSeenItemOfInterest);
        }
Пример #13
0
        public void OnAddedToGroup()
        {
            //save so the creature den spawner won't get confused
            //WorldItems.Get.Save(worlditem, true);
            //initialize the body parts
            //Body.Initialize (worlditem);
            //add the body's renderers to worlditem renderers
            //so they're disabled when appropriate
            //worlditem.Renderers.AddRange (Body.Renderers);

            if (Den == null)
            {
                IStackOwner owner = null;
                if (worlditem.Group.HasOwner(out owner))
                {
                    Den = (ICreatureDen)owner.worlditem.GetComponent(typeof(ICreatureDen));
                    //else - we don't have a den so we'll set default roaming distance from props
                }
            }
            if (Den != null)
            {
                Den.AddCreature(this.worlditem);
            }

            //set up the collective thought object
            CurrentThought.OnFleeFromIt += FleeFromThing;
            CurrentThought.OnKillIt     += AttackThing;
            CurrentThought.OnEatIt      += EatThing;
            CurrentThought.OnFollowIt   += FollowThing;
            CurrentThought.OnWatchIt    += WatchThing;
            //CurrentThought.OnMateWithIt += MateWithThing;

            Motile motile = null;

            if (worlditem.Is <Motile> (out motile))
            {
                //create motile behaviors
                //TODO create more logical behaviors for creatures without a den
                mFollowAction            = new MotileAction();
                mFollowAction.Name       = "Follow action by Creature";
                mFollowAction.Type       = MotileActionType.FollowTargetHolder;
                mFollowAction.FollowType = MotileFollowType.Follower;
                mFollowAction.Expiration = MotileExpiration.TargetOutOfRange;
                mFollowAction.OutOfRange = Den.Radius;
                mFollowAction.Range      = Den.Radius;
                //mFollowAction.TerritoryType = MotileTerritoryType.Den;
                mFollowAction.TerritoryBase = Den;

                mEatAction            = new MotileAction();
                mEatAction.Name       = "Eat action by Creature";
                mEatAction.Type       = MotileActionType.FollowGoal;
                mEatAction.Expiration = MotileExpiration.TargetInRange;
                mEatAction.Range      = Template.MotileTemplate.MotileProps.RVORadius * 2;
                //mEatAction.TerritoryType = MotileTerritoryType.Den;
                mEatAction.TerritoryBase = Den;

                mReturnToDenAction            = new MotileAction();
                mReturnToDenAction.Name       = "Return to Den action by Creature";
                mReturnToDenAction.Type       = MotileActionType.FollowGoal;
                mReturnToDenAction.Expiration = MotileExpiration.TargetInRange;
                mReturnToDenAction.Range      = Template.MotileTemplate.MotileProps.RVORadius;
                mReturnToDenAction.LiveTarget = Den.IOI;
                //mReturnToDenAction.TerritoryType = MotileTerritoryType.Den;
                mReturnToDenAction.TerritoryBase = Den;

                mFleeThreatAction               = new MotileAction();
                mFleeThreatAction.Name          = "Flee threat action by Creature";
                mFleeThreatAction.Type          = MotileActionType.FleeGoal;
                mFleeThreatAction.Expiration    = MotileExpiration.TargetOutOfRange;
                mFleeThreatAction.YieldBehavior = MotileYieldBehavior.DoNotYield;
                mFleeThreatAction.OutOfRange    = Den.Radius;
                mFleeThreatAction.Range         = Looker.AwarenessDistanceTypeToVisibleDistance(Template.LookerTemplate.AwarenessDistance);
                //mFleeThreatAction.TerritoryType = MotileTerritoryType.Den;
                mFleeThreatAction.TerritoryBase = Den;

                mPursueGoalAction               = new MotileAction();
                mPursueGoalAction.Name          = "Pursue goal action by Creature";
                mPursueGoalAction.Type          = MotileActionType.FollowGoal;
                mPursueGoalAction.Expiration    = MotileExpiration.TargetInRange;
                mPursueGoalAction.YieldBehavior = MotileYieldBehavior.YieldAndWait;
                mPursueGoalAction.Range         = Template.MotileTemplate.MotileProps.RVORadius;
                //mPursueGoalAction.TerritoryType = MotileTerritoryType.Den;
                mPursueGoalAction.TerritoryBase = Den;

                mFocusAction               = new MotileAction();
                mFocusAction.Name          = "Focus action by Creature";
                mFocusAction.Type          = MotileActionType.FocusOnTarget;
                mFocusAction.Expiration    = MotileExpiration.Duration;
                mFocusAction.RTDuration    = ShortTermMemoryToRT(Template.Props.ShortTermMemory);
                mFocusAction.YieldBehavior = MotileYieldBehavior.YieldAndFinish;
                //mFocusAction.TerritoryType = MotileTerritoryType.Den;
                mFocusAction.TerritoryBase = Den;

                mWanderAction            = motile.BaseAction;
                mWanderAction.Name       = "Base Action (wander) Set By Creature";
                mWanderAction.Type       = MotileActionType.WanderIdly;
                mWanderAction.LiveTarget = Den.IOI;
                //mWanderAction.TerritoryType = MotileTerritoryType.Den;
                mWanderAction.TerritoryBase = Den;
                mWanderAction.Range         = Den.Radius;
                mWanderAction.OutOfRange    = Den.Radius;

                if (!IsDead)
                {
                    motile.StartMotileActions();
                }
            }

            if (IsDead)
            {
                motile.IsRagdoll = true;
                Body.SetRagdoll(true, 0.1f);
                Body.transform.position = worlditem.transform.position + Vector3.up;
                Body.transform.Rotate(UnityEngine.Random.Range(0f, 360f), UnityEngine.Random.Range(0f, 360f), UnityEngine.Random.Range(0f, 360f));
                OnDie();
            }
            else
            {
                RefreshBehavior();
            }
        }
Пример #14
0
        public void FixedUpdate()
        {
            //TODO look into making this a coroutine
            mLookerCounter++;
            if (mLookerCounter > 2)
            {
                mLookerCounter = 0;
                if (SpawnedCharacters.Count > 0)
                {
                    Looker looker = null;
                    if (SharedLooker == null)
                    {
                        CreateSharedLooker();
                    }
                    if (!SharedLooker.IsInUse)
                    {
                        //if the looker is disabled that means it's done being used
                        mUpdateCharacterIndex = SpawnedCharacters.NextIndex(mUpdateCharacterIndex);
                        if (SpawnedCharacters [mUpdateCharacterIndex] != null)
                        {
                            if (SpawnedCharacters [mUpdateCharacterIndex].worlditem.Is <Looker> (out looker))
                            {
                                //listener is passive but looker is active
                                //it needs to be told to look for the player
                                //we stagger this because it's an expensive operation
                                looker.LookForStuff(SharedLooker);
                            }
                        }
                        else
                        {
                            SpawnedCharacters.RemoveAt(mUpdateCharacterIndex);
                        }
                    }
                }
            }

            if (SpawnedCharacters.Count == 0)
            {
                enabled = false;
            }

            if (CityAmbience == null)
            {
                return;
            }

            float distance = Vector3.Distance(Player.Local.Position, worlditem.Position);

            if (distance < worlditem.ActiveRadius)
            {
                //if we're in the city put the ambience right there
                CityAmbience.transform.position = Player.Local.Position;
            }
            else
            {
                //otherwise put it at the edge of the active radius
                CityAmbience.transform.position = Vector3.MoveTowards(worlditem.Position, Player.Local.Position, worlditem.ActiveRadius);
            }

            if (Player.Local.Surroundings.IsUnderground)
            {
                CityAmbience.volume = Mathf.Lerp(CityAmbience.volume, 0f, 0.1f);
            }
            else
            {
                float volume = distance / worlditem.ActiveRadius;
                if (Player.Local.Surroundings.IsInsideStructure)
                {
                    //cut the city ambience down by half
                    CityAmbience.volume = Mathf.Lerp(CityAmbience.volume, volume * 0.125f, 0.1f);
                }
                else
                {
                    CityAmbience.volume = Mathf.Lerp(CityAmbience.volume, volume, 0.1f);
                }
            }
        }
Пример #15
0
        public override void OnInitialized()
        {
            CharacterBody body = (CharacterBody)mBody;

            body.HairLength = State.HairLength;
            body.HairColor  = State.HairColor;

            animator = Body.GetComponent <CharacterAnimator> ();

            worlditem.OnGainPlayerFocus += OnGainPlayerFocus;
            worlditem.OnAddedToGroup    += OnAddedToGroup;
            worlditem.OnScriptAdded     += OnScriptAdded;
            worlditem.HudTargeter        = new HudTargetSupplier(HudTargeter);
            worlditem.OnPlayerCollide   += OnPlayerCollide;
            //set this so the body has something to lerp to
            if (mBody != null)
            {
                //this tells the body what to follow
                Motile motile = null;
                if (worlditem.Is <Motile> (out motile))
                {
                    if (Template.TemplateType == CharacterTemplateType.UniquePrimary || Template.TemplateType == CharacterTemplateType.UniqueAlternate)
                    {
                        motile.State.MotileProps.UseKinematicBody = false;
                    }
                    motile.BaseAction.WalkingSpeed = true;
                    mBody.OnSpawn(motile);
                }
                else
                {
                    mBody.OnSpawn(this);
                }
                mBody.transform.parent = worlditem.Group.transform;
                mBody.name             = worlditem.FileName + "-Body";
                mBody.Initialize(worlditem);
                if (State.Flags.Gender == 1)
                {
                    mBody.Sounds.MotionSoundType = MasterAudio.SoundType.CharacterVoiceMale;
                }
                else
                {
                    mBody.Sounds.MotionSoundType = MasterAudio.SoundType.CharacterVoiceFemale;
                }
            }

            Container container = null;

            if (worlditem.Is <Container> (out container))
            {
                container.CanOpen      = false;
                container.CanUseToOpen = false;
                container.OpenText     = "Search";
                FillStackContainer fillStackContainer = worlditem.Get <FillStackContainer> ();
                fillStackContainer.State.Flags    = State.Flags;
                fillStackContainer.State.FillTime = ContainerFillTime.OnOpen;
            }

            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.State.Result          = DamageableResult.Die;
            damageable.OnTakeDamage         += OnTakeDamage;
            damageable.OnTakeCriticalDamage += OnTakeCriticalDamage;
            damageable.OnTakeOverkillDamage += OnTakeOverkillDamage;
            damageable.OnDie += OnDie;

            mFollowAction            = new MotileAction();
            mFollowAction.Name       = "Follow action by Character";
            mFollowAction.Type       = MotileActionType.FollowTargetHolder;
            mFollowAction.Expiration = MotileExpiration.TargetOutOfRange;
            mFollowAction.Range      = 10f;

            mSleepAction            = new MotileAction();
            mSleepAction.Name       = "Sleep action by Character";
            mSleepAction.Type       = MotileActionType.Wait;
            mSleepAction.Expiration = MotileExpiration.Never;
            mSleepAction.Range      = 10f;

            mFleeThreatAction               = new MotileAction();
            mFleeThreatAction.Name          = "Flee threat action by Character";
            mFleeThreatAction.Type          = MotileActionType.FleeGoal;
            mFleeThreatAction.Expiration    = MotileExpiration.TargetOutOfRange;
            mFleeThreatAction.YieldBehavior = MotileYieldBehavior.DoNotYield;
            mFleeThreatAction.OutOfRange    = 10f;
            mFleeThreatAction.Range         = Looker.AwarenessDistanceTypeToVisibleDistance(Template.LookerTemplate.AwarenessDistance);

            mPursueGoalAction               = new MotileAction();
            mPursueGoalAction.Name          = "Pursue goal action by Character";
            mPursueGoalAction.Type          = MotileActionType.FollowGoal;
            mPursueGoalAction.Expiration    = MotileExpiration.TargetInRange;
            mPursueGoalAction.YieldBehavior = MotileYieldBehavior.YieldAndWait;
            mPursueGoalAction.Range         = Template.MotileTemplate.MotileProps.RVORadius * 1.5f;

            mFocusAction               = new MotileAction();
            mFocusAction.Name          = "Focus action by Character";
            mFocusAction.Type          = MotileActionType.FocusOnTarget;
            mFocusAction.Expiration    = MotileExpiration.TargetOutOfRange;
            mFocusAction.RTDuration    = 5f;
            mFocusAction.Range         = 10f;
            mFocusAction.OutOfRange    = 15f;
            mFocusAction.WalkingSpeed  = true;
            mFocusAction.YieldBehavior = MotileYieldBehavior.YieldAndFinish;
        }