public override void OnInitialized() { Damageable damageable = null; if (!worlditem.Is <Damageable> (out damageable)) { //Debug.Log ("Demolishable requires damageable"); Finish(); return; } damageable.OnTakeDamage += OnTakeDamage; if (State.UseDemolitionController) { //if we're supposed to use a demolition controller find that now Invoke("LookForDemolitionController", 1f); } }
public override void OnInitialized() { //set quest name so it's treated as a quest item worlditem.Props.Name.QuestName = State.QuestName; worlditem.Props.Name.DisplayName = State.DisplayName; Missions.Get.AddQuestItem(worlditem); worlditem.OnPlayerCarry += OnPlayerCarry; Damageable damageable = null; if (worlditem.Is <Damageable>(out damageable)) { damageable.OnDie += OnDie; } worlditem.OnStateChange += OnStateChange; worlditem.OnAddedToGroup += OnAddedToGroup; worlditem.OnAddedToPlayerInventory += OnAddedToPlayerInventory; GameWorld.Get.ActiveQuestItems.SafeAdd(worlditem); }
public void Update() { if (!mInitialized) { return; } State.StrengthLost += (float)(mMotile.CurrentMovementSpeed * State.StrengthLossPerMeterPerMinute * WorldClock.DeltaTimeMinutes); float normalizedStrength = State.NormalizedStrength; if (normalizedStrength <= 0.0f) { Damageable damageable = null; if (worlditem.Is <Damageable>(out damageable)) { damageable.InstantKill(WIMaterialType.None, "Exhaustion", false); } else { worlditem.SetMode(WIMode.Destroyed); Finish(); } } if (mFeebleElement != null) { mFeebleElement.ProgressValue = normalizedStrength; if (normalizedStrength < 0.5f) { mFeebleElement.Ping(0.5f); } else { mFeebleElement.StopPing(); } } }
public void OnTakeDamage( ) { Debug.Log("taking damage in demolishable"); Damageable damageable = null; if (worlditem.Is <Damageable> (out damageable)) { //check to see if the force exceeded our threshold Vector3 lastForce = damageable.State.LastDamageForce; if (lastForce.magnitude > State.MaximumForce) { //instant kill damageable.State.DamageTaken = damageable.State.Durability; OnDemolished.SafeInvoke(); Debug.Log("We are demolished"); } else { damageable.ResetDamage(); Debug.Log("last force " + lastForce.magnitude.ToString() + " wasn't enough to kill " + State.MaximumForce.ToString()); } } }
public override void OnInitialized() { worlditem.ActiveStateLocked = false; worlditem.ActiveState = WIActiveState.Active; worlditem.ActiveStateLocked = true; Detectable detectable = worlditem.Get <Detectable> (); detectable.OnPlayerDetect += OnPlayerDetect; FoodStuff foodStuff = worlditem.Get <FoodStuff> (); foodStuff.OnEat += OnEat; foodStuff.State.ConsumeOnEat = false; //we'll handle consumption Damageable damageable = worlditem.Get <Damageable> (); damageable.OnDie += OnDie; if (HasBeenPicked) { RefreshPlantProps(); } }
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 override void OnInitialized() { damageable = worlditem.Get <Damageable>(); damageable.OnDie += OnDie; }
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; }