示例#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 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);
        }
示例#3
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();
            }
        }
示例#4
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;
        }