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); }
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); } }
protected IEnumerator ChasePlayerOverTime( ) { Transform targetHolderTransform = gameObject.CreateChild("TargetHolder"); GuardsFollowTarget = targetHolderTransform.gameObject.AddComponent <RVOTargetHolder> (); for (int i = 0; i < SpawnedGuards.Count; i++) { MotileAction chasePlayerAction = new MotileAction(); chasePlayerAction.Type = MotileActionType.FollowTargetHolder; chasePlayerAction.LiveTargetHolder = GuardsFollowTarget; chasePlayerAction.FollowType = MotileFollowType.Follower; chasePlayerAction.Expiration = MotileExpiration.Never; chasePlayerAction.YieldBehavior = MotileYieldBehavior.DoNotYield; SpawnedGuards [i].worlditem.Get <Motile> ().PushMotileAction(chasePlayerAction, MotileActionPriority.ForceTop); } while (!HasCaughtPlayer) { State.PursuitDistanceSoFar = GuardPath.GetClosestPointParam(Player.Local.Position, 1, 0f, 1f, 0.01f); targetHolderTransform.position = GuardPath.GetPositionOnSpline(State.PursuitDistanceSoFar); State.PursuitDistanceSoFar += (float)(WorldClock.ARTDeltaTime * 0.005f); yield return(null); } mChasingPlayer = false; yield break; }
//convenience public MotileAction LookAtPlayer() { FXManager.Get.SpawnFX(Body.Transforms.HeadTop, "ListenEffect", UnityEngine.Random.value); MotileAction lookAtPlayerAction = WatchThingAction(Player.Local); lookAtPlayerAction.Name = "LookAtPlayer"; if (!lookAtPlayerAction.HasStarted) { MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "NpcNoticePlayer"); } return(lookAtPlayerAction); }
public override void OnInitialized() { mMotile = worlditem.Get <Motile>(); mFollowAction = new MotileAction(); mFollowAction.Type = MotileActionType.FollowTargetHolder; mFollowAction.FollowType = MotileFollowType.Follower; mFollowAction.Expiration = MotileExpiration.Never; mFollowAction.LiveTarget = Player.Local; mFollowAction.Instructions = MotileInstructions.PilgrimInstructions; mMotile.PushMotileAction(mFollowAction, MotileActionPriority.ForceBase); StartCoroutine(CheckFollowAction()); }
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; }
public void HearCommand(SpeechBubble audibleSpeech, string command) { if (audibleSpeech.Speaker.worlditem == worlditem) //can't react to your own speeches { return; } Motile motile = null; if (worlditem.Is <Motile> (out motile)) { MotileAction topAction = motile.TopAction; MotileAction newAction = new MotileAction(); newAction.Target = new MobileReference(audibleSpeech.Speaker.worlditem.FileName, audibleSpeech.Speaker.worlditem.Group.Props.PathName); newAction.LiveTarget = audibleSpeech.Speaker.worlditem; MotileActionPriority priority = MotileActionPriority.ForceTop; switch (command) { case "Listen": FXManager.Get.SpawnFX(motile.Body.Transforms.HeadTop, "ListenEffect"); if (!IsListeningTo(audibleSpeech)) { if (topAction.Type == MotileActionType.GoToActionNode) { priority = MotileActionPriority.Next; } ////Debug.Log ("Listener is listening to speaker " + audibleSpeech.Speaker.name); if (mListenAction == null) { mListenAction = new MotileAction(); } mListenAction.Type = MotileActionType.FocusOnTarget; mListenAction.Expiration = MotileExpiration.TargetOutOfRange; mListenAction.OutOfRange = audibleSpeech.ParentSpeech.AudibleRange * 2.0f; mListenAction.Target = new MobileReference(audibleSpeech.Speaker.worlditem.FileName, audibleSpeech.Speaker.worlditem.Group.Props.PathName); mListenAction.LiveTarget = audibleSpeech.Speaker.worlditem; mListenAction.YieldBehavior = MotileYieldBehavior.YieldAndFinish; motile.PushMotileAction(mListenAction, priority); } break; case "FollowSpeaker": if (!IsFollowing(audibleSpeech)) { //Debug.Log ("Listener is following speaker " + audibleSpeech.Speaker.name); if (mFollowAction == null) { mFollowAction = new MotileAction(); } mFollowAction.Type = MotileActionType.FollowTargetHolder; mFollowAction.LiveTarget = audibleSpeech.Speaker.worlditem; mFollowAction.Target = new MobileReference(audibleSpeech.Speaker.worlditem.FileName, audibleSpeech.Speaker.worlditem.Group.Props.PathName); mFollowAction.Expiration = MotileExpiration.Duration; mFollowAction.RTDuration = 600.0f; mFollowAction.YieldBehavior = MotileYieldBehavior.DoNotYield; motile.PushMotileAction(mFollowAction, priority); } break; case "StopListeningAndFollowing": if (IsListeningTo(audibleSpeech)) { mListenAction.TryToFinish(); } if (IsFollowing(audibleSpeech)) { mFollowAction.TryToFinish(); } break; case "StopListening": if (IsListeningTo(audibleSpeech)) { mListenAction.TryToFinish(); } break; case "StopFollowing": if (IsFollowing(audibleSpeech)) { mFollowAction.TryToFinish(); } break; case "LookAtPlayer": FXManager.Get.SpawnFX(motile.Body.Transforms.HeadTop, "ListenEffect", UnityEngine.Random.value * 3f); worlditem.Get <Character> ().LookAtPlayer(); break; default: break; } } }
protected IEnumerator SeekResources(bool isMeteor) { //Debug.Log ("Seeking resources, meteor? " + isMeteor.ToString ()); IItemOfInterest thingToSeek = null; if (isMeteor) { if (HasMeteorToGather) { thingToSeek = mMeteorToGather.worlditem; } else { BehaviorState = OrbBehaviorState.ConsideringOptions; yield break; } //Debug.Log ("No longer has meteor to seek, stoppping"); } else { if (HasLuminiteToGather) { thingToSeek = mLuminiteToGather.worlditem; } else { BehaviorState = OrbBehaviorState.ConsideringOptions; } yield break; } //Debug.Log ("Seeking resource " + thingToSeek.gameObject.name); MotileAction seekAction = creature.FollowThingAction(thingToSeek); seekAction.Terrain = TerrainType.AllButCivilization; seekAction.Expiration = MotileExpiration.TargetInRange; seekAction.FollowType = MotileFollowType.Follower; seekAction.Range = motile.State.MotileProps.RVORadius * 5; bool keepSeeking = true; while (keepSeeking) { //Debug.Log ("Seeking meteor..."); if (seekAction.IsFinished) { //if we're in range it's time to eat our meteor //Debug.Log ("Seek action was finished and we're in range, so we're eating"); BehaviorState = isMeteor ? OrbBehaviorState.EatingMeteor : OrbBehaviorState.EatingLuminite; yield break; } double waitUntil = WorldClock.AdjustedRealTime + 0.05f; while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } if (isMeteor) { keepSeeking = HasMeteorToGather && BehaviorState == OrbBehaviorState.SeekingMeteor; } else { keepSeeking = HasLuminiteToGather && BehaviorState == OrbBehaviorState.SeekingLuminite; } } if (!seekAction.IsFinished) { //if we're still seeking the meteor //try to stop motile seekAction.TryToFinish(); } yield break; }
protected IEnumerator SeekItemOfInterest() { if (ThingToInvestigate == null) { BehaviorState = OrbBehaviorState.ConsideringOptions; yield break; } IItemOfInterest startThingToInvestigate = ThingToInvestigate; MotileAction seekAction = creature.FollowThingAction(startThingToInvestigate); seekAction.Name = "Seek " + startThingToInvestigate.gameObject.name + " by Orb"; seekAction.Expiration = MotileExpiration.Duration; seekAction.RTDuration = 5f; while (HasThingToInvestigate && ThingToInvestigate == startThingToInvestigate && BehaviorState == OrbBehaviorState.SeekingItemOfInterest) { if (seekAction.IsFinished) { OrbSpeak(OrbSpeakUnit.ResumingNormalRoutine, worlditem.tr); //if we're finished but not in range something happened BehaviorState = OrbBehaviorState.ConsideringOptions; yield break; } else if (seekAction.IsInRange) { OrbSpeak(OrbSpeakUnit.TargetIsStrangeInvestigatingTarget, worlditem.tr); double scanTime = WorldClock.AdjustedRealTime + 1.5f; FXManager.Get.SpawnFX(startThingToInvestigate, "ScanEffect"); MasterAudio.PlaySound(MasterAudio.SoundType.Machines, startThingToInvestigate.gameObject.transform, "ScanSound"); while (WorldClock.AdjustedRealTime < scanTime) { yield return(null); } if (ThingToInvestigate == startThingToInvestigate) { ThingToInvestigate = null; } } double waitUntil = WorldClock.AdjustedRealTime + 1f; while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } } if (!seekAction.IsFinished && seekAction.LiveTarget == startThingToInvestigate) { //if we're still seeking the meteor //try to stop motile seekAction.TryToFinish(); } if (ThingToInvestigate == startThingToInvestigate) { //clear it unless it has changed ThingToInvestigate = null; } yield break; }
protected IEnumerator MineResources(bool isMeteor) { WorldItem thingToGather = null; if (isMeteor) { if (HasMeteorToGather) { thingToGather = mMeteorToGather.worlditem; } else { BehaviorState = OrbBehaviorState.ConsideringOptions; yield break; } } else { if (HasLuminiteToGather) { thingToGather = mLuminiteToGather.worlditem; } else { BehaviorState = OrbBehaviorState.ConsideringOptions; } yield break; } //Debug.Log ("Starting item mining process"); double startEatTime = WorldClock.AdjustedRealTime; double finishMiningTime = WorldClock.AdjustedRealTime + MeteorEatTime; float damageOnStart = 0f; Damageable itemDamageable = thingToGather.Get <Damageable> (); if (itemDamageable != null) { damageOnStart = itemDamageable.NormalizedDamage; } MotileAction waitAction = creature.WatchThingAction(thingToGather); waitAction.Expiration = MotileExpiration.TargetOutOfRange; waitAction.OutOfRange = 25f; OrbSpeak(OrbSpeakUnit.MiningLuminite, worlditem.tr); bool keepMining = true; while (keepMining) { if (mPowerBeam == null) { mPowerBeam = GetPowerBeam(); } mPowerBeam.AttachTo(LuminiteGemPivot, thingToGather); mPowerBeam.WarmUp(); mPowerBeam.Fire(0.45f); if (waitAction.IsFinished || waitAction.LiveTarget != thingToGather) { //something has interrupted us //Debug.Log ("Wait action was finished or had a different target, stopping motile action"); BehaviorState = OrbBehaviorState.ConsideringOptions; } else { if (itemDamageable != null && itemDamageable.NormalizedDamage > damageOnStart) { //Debug.Log ("Something damaged the meteor, checking out what"); mPowerBeam.StopFiring(); OrbSpeak(OrbSpeakUnit.TargetBehavingErratically, worlditem.tr); //look at the thing that last hit it ThingToInvestigate = itemDamageable.LastDamageSource; BehaviorState = OrbBehaviorState.SeekingItemOfInterest; } else if (WorldClock.AdjustedRealTime > finishMiningTime) { //Debug.Log ("Done eating!"); //it's toast! kill it //force it to not spawn any items on die FXManager.Get.SpawnExplosionFX(ExplosionType.Base, null, thingToGather.Position); thingToGather.worlditem.RemoveFromGame(); if (isMeteor) { NumMeteorsGathered++; } else { NumLuminiteGathered++; } } } double waitUntil = WorldClock.AdjustedRealTime + 0.125f; while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } if (isMeteor) { keepMining = HasMeteorToGather && thingToGather == MeteorToGather.worlditem && BehaviorState == OrbBehaviorState.EatingMeteor; } else { keepMining = HasLuminiteToGather && thingToGather == MeteorToGather.worlditem && BehaviorState == OrbBehaviorState.EatingLuminite; } } if (mPowerBeam != null) { mPowerBeam.StopFiring(); } BehaviorState = OrbBehaviorState.ConsideringOptions; yield break; }
public IEnumerator FollowRoutineOverTime() { while (!motile.Initialized || !motile.HasBody) { yield return(null); } //wait for a random interval to reduce the load on the city double waitUntil = WorldClock.AdjustedRealTime + UnityEngine.Random.value; while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } if (ParentSite == null) { //Debug.Log ("Parent site was null in " + name + ", removing routine"); Finish(); yield break; } //Debug.Log (worlditem.Group.Props.TerrainType.ToString () + " in " + worlditem.name); //if we don't have a parent site within a second of spawning then we're toast if (!ParentSite.HasMovementNodes(worlditem.Group.Props.TerrainType, worlditem.Group.Props.Interior, OccupationFlags)) { //Debug.Log ("Parent site " + ParentSite.name + " had no movement nodes, quitting routine"); Finish(); yield break; } while (!ParentSite.IsActive(worlditem.Group.Props.TerrainType, worlditem.Group.Props.Interior, OccupationFlags)) { yield return(null); } //get the very first node we'll be using LastMovementNode = ParentSite.GetNodeNearest(worlditem.Position, worlditem.Group.Props.TerrainType, worlditem.Group.Props.Interior, OccupationFlags); //DAILY ROUTINE START while (!(mFinished | mDestroyed)) { //wait a random amount waitUntil = WorldClock.AdjustedRealTime + (UnityEngine.Random.value * 4f); while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } //if we're not visible then just hang out while (worlditem.Is(WIActiveState.Invisible)) { waitUntil = WorldClock.AdjustedRealTime + 0.25f; while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } } //get the next movement node LastMovementNode = ParentSite.GetNextNode(LastMovementNode, worlditem.Group.Props.TerrainType, worlditem.Group.Props.Interior, OccupationFlags); if (MovementNode.IsEmpty(LastMovementNode)) { //Debug.Log ("Node was empty in routine from " + ParentSite.name + ", ending routine"); mFollowingRoutine = false; Finish(); yield break; } //Debug.Log ("Going to last movement node " + LastMovementNode.Index.ToString () + " at position " + LastMovementNode.Position.ToString ()); motile.GoalObject.position = LastMovementNode.Position; MotileAction goToAction = character.GoToThing(null); goToAction.Range = 1.5f; goToAction.WalkingSpeed = true; //now wait until we get there float maxWaitTime = 30f; double startTime = WorldClock.AdjustedRealTime; var waitUntilFinished = goToAction.WaitForActionToFinish(0.15f); while (waitUntilFinished.MoveNext()) { //Debug.Log ("Waiting for action to finish, state is " + goToAction.State.ToString ()); if (goToAction.State != MotileActionState.Waiting) { motile.GoalObject.position = LastMovementNode.Position; } yield return(waitUntilFinished.Current); if (WorldClock.AdjustedRealTime > startTime + maxWaitTime) { //Debug.Log ("Timed out, finishing now"); goToAction.TryToFinish(); break; } } yield return(null); } mFollowingRoutine = false; yield break; }
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(); } }
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; }
protected IEnumerator FollowPathOverTime() { //create the motile action and push it first yield return(null); if (mFollowPathAction == null) { mFollowPathAction = new MotileAction(); mFollowPathAction.Type = MotileActionType.FollowGoal; mFollowPathAction.Expiration = MotileExpiration.Never; mFollowPathAction.YieldBehavior = MotileYieldBehavior.YieldAndWait; mFollowPathAction.LiveTarget = this; mFollowPathAction.Range = 2f; mFollowPathAction.OutOfRange = 100f; mFollowPathAction.Name = "PilgrimFollowPath"; } else { mFollowPathAction.Reset(); } Motile motile = worlditem.Get <Motile>(); motile.PushMotileAction(mFollowPathAction, MotileActionPriority.ForceTop); State.PathMode = FollowPathMode.FollowingPath; yield return(null); while (State.PathMode != FollowPathMode.None) //check the state of the motile action we submitted { switch (mFollowPathAction.State) { case MotileActionState.Started: case MotileActionState.Starting: //hooray, it has started, update the path //set it to reached pilgrim stop to force us to go to the next stop var updateFollowPath = UpdateFollowPath(); while (updateFollowPath.MoveNext()) { yield return(updateFollowPath.Current); } //now see if the path has finished or whatever switch (State.PathMode) { case FollowPathMode.None: //case FollowPathMode.ReachedEndOfPath: //hooray we're done //yield return StartCoroutine(FinishFollowingPath()); break; default: //keep going //this includes waiting for an obstruction break; } break; case MotileActionState.Error: case MotileActionState.Finished: //whoops, we're done on the Motile end for some reason //maybe we're dead or maybe we got a conflicting command yield return(StartCoroutine(FinishFollowingPath())); break; case MotileActionState.Waiting: //we're being talked to or something, just hang out break; default: break; } //wait for a bit yield return(gWaitForFollowPath); } mFollowingPathOverTime = false; yield break; }