Ejemplo n.º 1
0
        public void OnLocationGroupLoaded()
        {
            Structures.AddMinorToload(State.GraveyardStructure, 0, worlditem);

            if (!State.CreatedHeadstones)
            {
                //create headstones the first time we load the location group
                //after that they'll just load and unload normally
                WorldItem headstoneWorldItem = null;
                State.CreatedHeadstones = true;
                for (int i = 0; i < State.HeadstoneSpawnPoints.Count; i++)
                {
                    if (WorldItems.CloneRandomFromCategory(State.HeadstoneCategory, location.LocationGroup, State.HeadstoneSpawnPoints[i], out headstoneWorldItem))
                    {
                        headstoneWorldItem.Initialize();
                        HeadstoneAvatar hsa = headstoneWorldItem.Get <HeadstoneAvatar>();
                        if (i < State.Headstones.Count)
                        {
                            hsa.State.HeadstoneName = State.Headstones[i];
                        }
                        hsa.RefreshProps();
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void OnGetItemClick(GameObject go)
 {
     if (_nearWorldItem != null)
     {
         _nearWorldItem.Get(_gameManager);
         _nearWorldItem = null;
     }
 }
Ejemplo n.º 3
0
        protected IEnumerator LaunchProjectile(Equippable equippable, Weapon weapon)
        {
            if (!HasProjectile)
            {
                //if we don't have a projectile it doesn't matter
                //MasterAudio.PlaySound (mEquippable.Sounds.SoundType, ToolDoppleganger.transform, mEquippable.Sounds.SoundUseUnuccessfully);
                mEquippable.UseUnsuccessfully();
                ToolState = PlayerToolState.Equipped;
                yield break;
            }
            //convert the projectile object to a world item if it isn't already
            Projectile projectile = null;

            if (ProjectileObject.IsWorldItem)
            {
                //get the projectile from the existing worlditem
                projectile = ProjectileObject.worlditem.Get <Projectile>();
            }
            else
            {
                WorldItem worlditemProjectile = null;
                //clone the projectile from the stack item
                WorldItems.CloneFromStackItem(ProjectileObject.GetStackItem(WIMode.Stacked), WIGroups.Get.Player, out worlditemProjectile);
                //initialize immediately
                worlditemProjectile.Initialize();
                worlditemProjectile.transform.position = ToolActionPointObject.position;
                worlditemProjectile.transform.rotation = ToolActionPointObject.rotation;
                //set the projectile object to null
                ProjectileObject = null;
                //give it a second to initialze
                projectile = worlditemProjectile.Get <Projectile>();
            }

            if (projectile != null)
            {
                projectile.Launch(ToolActionPointObject, weapon, LaunchForce);
                //play the launching sound
                mEquippable.UseSuccessfully();
                //MasterAudio.PlaySound (mEquippable.Sounds.SoundType, ToolDoppleganger.transform, mEquippable.Sounds.SoundUseSuccessfully);
                yield return(null);
            }
            else
            {
                Debug.Log("Projectile was null");
            }
            RefreshToolDoppleganger(false);
            yield return(null);

            if (UsesTensionMorph)
            {
                TensionChannel.Percent = 0f;
            }
            yield break;
        }
Ejemplo n.º 4
0
        public void LookForDemolitionController( )
        {
            WorldItem demolitionControllerWorldItem = null;

            if (WIGroups.FindChildItem(State.DemolitionControllerPath, out demolitionControllerWorldItem))
            {
                DemolitionController = demolitionControllerWorldItem.Get <StructureDemolitionController> ();
                DemolitionController.AddDemolishable(this);
                //don't let our colliders turn off
                worlditem.ActiveState       = WIActiveState.Active;
                worlditem.ActiveStateLocked = true;
            }
        }
Ejemplo n.º 5
0
        public override void OnActivated()
        {
            WorldItem structureWorldItem = null;
            StackItem structureStackitem = null;

            if (WIGroups.FindChildItem(StructurePath, out structureWorldItem))
            {
                if (Player.Local.Surroundings.IsVisitingStructure(structureWorldItem.Get <Structure> ()))
                {
                    HasCompleted = true;
                }
            }
        }
Ejemplo n.º 6
0
        protected IEnumerator FillWearablesOverTime(string categoryName)
        {
            //wait a frame
            yield return(null);

            //Debug.Log("Filling wearables from category " + categoryName);
            WICategory category = null;
            STransform tr       = new STransform();

            if (WorldItems.Get.Category(categoryName, out category))
            {
                //Debug.Log("Got category, filling now");
                for (int i = 0; i < category.GenericWorldItems.Count; i++)
                {
                    //get an instance of the item and try to wear it
                    //Debug.Log("Adding wearable " + category.GenericWorldItems[i].DisplayName);
                    for (int j = 0; j < category.GenericWorldItems[i].InstanceWeight; j++)
                    {
                        WorldItem newWorldItem = null;
                        if (WorldItems.CloneWorldItem(category.GenericWorldItems[i], tr, false, WIGroups.Get.Player, out newWorldItem))
                        {
                            newWorldItem.Initialize();
                            Wearable wearable = newWorldItem.Get <Wearable>();
                            if (!Wear(wearable))
                            {
                                //if we can't wear it for some reason, drop it in front of the player
                                player.ItemPlacement.ItemDropAtFeet(newWorldItem);
                            }
                            else
                            {
                                //Debug.Log("Player has been equipped with " + newWorldItem.DisplayName);
                            }
                        }
                    }
                }
            }
            else
            {
                //Debug.Log("Couldn't find category " + categoryName);
            }
            yield break;
        }
Ejemplo n.º 7
0
        public IEnumerator SendPlayerToHealingBed()
        {
            worlditem.ActiveState = WIActiveState.Active;
            Structure structure = worlditem.Get <Structure>();

            while (!structure.Is(StructureLoadState.ExteriorLoaded))
            {
                yield return(null);
            }
            Structures.AddInteriorToLoad(structure);
            while (!structure.Is(StructureLoadState.InteriorLoaded))
            {
                yield return(null);
            }
            Player.Local.Spawn();
            //find the first bed
            List <WorldItem> bedWorldItems = structure.StructureGroup.GetChildrenOfType(new List <string>()
            {
                "Bed"
            });

            while (bedWorldItems.Count == 0)
            {
                double waitUntil = Frontiers.WorldClock.AdjustedRealTime + 0.1f;
                while (Frontiers.WorldClock.AdjustedRealTime < waitUntil)
                {
                    yield return(null);
                }
                bedWorldItems = structure.StructureGroup.GetChildrenOfType(new List <string>()
                {
                    "Bed"
                });
            }
            WorldItem bedWorldItem = bedWorldItems[UnityEngine.Random.Range(0, bedWorldItems.Count)];
            Bed       bed          = bedWorldItem.Get <Bed>();

            Player.Local.transform.position = bed.BedsidePosition;
            bed.TryToSleep(WorldClock.Get.TimeOfDayAfter(WorldClock.TimeOfDayCurrent));
            yield break;
        }
Ejemplo n.º 8
0
        protected IEnumerator WaitForBodiesOfWater()
        {
            bool waitForTop    = !string.IsNullOrEmpty(State.TopBodyOfWaterPath);
            bool waitForBottom = !string.IsNullOrEmpty(State.BottomBodyOfWaterPath);

            while (waitForTop | waitForBottom)
            {
                if (waitForTop)
                {
                    WorldItem bodyOfWaterWorlditem = null;
                    if (WIGroups.FindChildItem(State.TopBodyOfWaterPath, out bodyOfWaterWorlditem))
                    {
                        BodyOfWater bodyOfWater = bodyOfWaterWorlditem.Get <BodyOfWater> ();
                        WaterfallTopFollow = bodyOfWater.WaterPivot.transform;
                        waitForTop         = false;
                    }
                }
                if (waitForBottom)
                {
                    WorldItem bodyOfWaterWorlditem = null;
                    if (WIGroups.FindChildItem(State.BottomBodyOfWaterPath, out bodyOfWaterWorlditem))
                    {
                        BodyOfWater bodyOfWater = bodyOfWaterWorlditem.Get <BodyOfWater> ();
                        WaterfallBottomFollow = bodyOfWater.WaterPivot.transform;
                        waitForBottom         = false;
                    }
                }
                double waitUntil = Frontiers.WorldClock.AdjustedRealTime + 0.5f;
                while (Frontiers.WorldClock.AdjustedRealTime < waitUntil)
                {
                    yield return(null);
                }
                //Debug.Log ("Waiting for top / bottom: " + waitForTop.ToString () + " / " + waitForBottom.ToString ());
            }
            enabled = true;
            yield break;
        }
Ejemplo n.º 9
0
 protected void StartupStructureLoaded(WorldItem mStartupStructureWorldItem)
 {
     mStartupStructureWorldItem.Initialize();
     mStartupStructure = mStartupStructureWorldItem.Get <Structure> ();
 }
Ejemplo n.º 10
0
        //this function is meant to be used with the HouseOfHealing skill
        //i've only been able to get this process to work a few times
        //the idea is to super-load the last visited HOH
        //then load its interior and put the player in one of its beds
        //great in theory but in practice something always f***s up
        protected IEnumerator SpawnInClosestStructureOverTime(Vector3 despawnPosition, List <MobileReference> structureReferences, Action <Bed> OnFinishAction)
        {
            if (mSpawningPlayer)
            {
                //whoops
                yield break;
            }
            mSpawningPlayer = true;

            CurrentStartupPosition = null;

            float           closestDistanceSoFar           = Mathf.Infinity;
            StackItem       closestStructureStateSoFar     = null;
            StackItem       currentStructureState          = null;
            MobileReference currentStructureReference      = null;
            MobileReference closestStructureReferenceSoFar = null;
            Vector3         closestStructurePositionSoFar  = despawnPosition;
            WorldChunk      currentChunk = null;

            //find out which structure is the closest
            for (int i = 0; i < structureReferences.Count; i++)
            {
                currentStructureReference = structureReferences [i];
                //Debug.Log ("SPAWNMANAGER: Checking structure reference " + currentStructureReference.FullPath.ToString ());
                if (WIGroups.LoadStackItem(currentStructureReference, out currentStructureState))
                {
                    if (currentStructureState.Is <Structure> ())
                    {
                        //get the chunk for this item
                        if (GameWorld.Get.ChunkByID(currentStructureReference.ChunkID, out currentChunk))
                        {
                            Vector3 structureWorldPosition = WorldChunk.ChunkPositionToWorldPosition(currentChunk.ChunkBounds, currentStructureState.ChunkPosition);
                            structureWorldPosition += currentChunk.ChunkOffset;
                            float currentDistance = Vector3.Distance(despawnPosition, structureWorldPosition);
                            if (currentDistance < closestDistanceSoFar)
                            {
                                closestDistanceSoFar           = currentDistance;
                                closestStructureStateSoFar     = currentStructureState;
                                closestStructureReferenceSoFar = currentStructureReference;
                                closestStructurePositionSoFar  = structureWorldPosition;
                            }
                        }
                    }
                }
            }

            if (closestStructureStateSoFar == null)
            {
                yield break;
            }

            //move the player to the position of the new item
            //this will help us to super-load the structure
            Player.Local.Position = closestStructurePositionSoFar;

            //reset the current loading structure
            mSpawnStructureWorldItem = null;
            Structure spawnStructure = null;
            Bed       loadedBed      = null;

            //super-load the item
            //yield return null;
            //WorldItems.Get.SuspendActiveStateChecking = true;
            StartCoroutine(WIGroups.SuperLoadChildItem(closestStructureReferenceSoFar.GroupPath, closestStructureReferenceSoFar.FileName, SpawnStructureLoaded, 0f));
            WIGroup lastGroupLoaded = null;

            while (mSpawnStructureWorldItem == null)
            {
                yield return(null);
            }

            //WorldItems.Get.SuspendActiveStateChecking = false;
            //okay next we have to load the structure interior
            mSpawnStructureWorldItem.ActiveStateLocked = false;
            mSpawnStructureWorldItem.ActiveState       = WIActiveState.Active;
            mSpawnStructureWorldItem.ActiveStateLocked = true;
            yield return(null);

            //now that the player is where they're supposed to be we can resume active state checking
            //but keep the structure itself locked
            //Player.Local.Position = mSpawnStructureWorldItem.Position;
            //ColoredDebug.Log ("Sending player to spawn structure position " + mSpawnStructureWorldItem.Position.ToString (), "Yellow");

            spawnStructure = mSpawnStructureWorldItem.Get <Structure> ();
            spawnStructure.LoadPriority = StructureLoadPriority.SpawnPoint;
            if (spawnStructure.Is(StructureLoadState.ExteriorUnloaded))
            {
                yield return(StartCoroutine(spawnStructure.CreateStructureGroups(StructureLoadState.ExteriorLoaded)));

                Structures.AddExteriorToLoad(spawnStructure);
                while (spawnStructure.Is(StructureLoadState.ExteriorLoading | StructureLoadState.ExteriorWaitingToLoad))
                {
                    yield return(null);
                }
            }
            if (spawnStructure.Is(StructureLoadState.ExteriorLoaded))
            {
                Structures.AddInteriorToLoad(spawnStructure);
                while (spawnStructure.Is(StructureLoadState.InteriorWaitingToLoad | StructureLoadState.InteriorLoading))
                {
                    yield return(null);
                }
                spawnStructure.RefreshColliders(true);
                spawnStructure.RefreshRenderers(true);
                //finally we search for a bed
            }
            spawnStructure.StructureGroup.Load();
            while (!spawnStructure.StructureGroup.Is(WIGroupLoadState.Loaded))
            {
                yield return(null);
            }

            yield return(null);

            //wait a tick to let the group catch up
            //wait a tick to let the group catch up
            yield return(null);

            List <WorldItem> bedWorldItems = new List <WorldItem> ();

            while (bedWorldItems.Count == 0)
            {
                yield return(StartCoroutine(WIGroups.GetAllChildrenByType(spawnStructure.StructureGroup.Props.PathName, new List <string> ()
                {
                    "Bed"
                }, bedWorldItems, spawnStructure.worlditem.Position, Mathf.Infinity, 1)));

                //can't use WaitForSeconds because timescale will be zero
                double waitUntil = WorldClock.RealTime + 0.1f;
                while (WorldClock.RealTime < waitUntil)
                {
                    yield return(null);
                }
            }

            WorldItem bedWorldItem = bedWorldItems [0];

            while (!bedWorldItem.Is(WILoadState.Initialized))
            {
                yield return(null);
            }
            loadedBed = bedWorldItem.Get <Bed> ();
            //Player.Local.Position = loadedBed.BedsidePosition;
            mSpawningPlayer = false;
            mSpawnStructureWorldItem.ActiveStateLocked = false;
            OnFinishAction(loadedBed);
            Player.Local.Surroundings.StructureEnter(spawnStructure);
            yield break;
        }
Ejemplo n.º 11
0
        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;
        }
Ejemplo n.º 12
0
        public void Update()
        {
            if (!SpawnMeteors)
            {
                return;
            }

            RecentMeteorMaterial.color = Color.Lerp(GlowMaterialColorDark, GlowMaterialColor, Mathf.Abs(Mathf.Sin(Time.time)));

                        #if UNITY_EDITOR
            if (Input.GetKeyDown(KeyCode.O))
            {
                if (InactiveMeteors.Count > 0)
                {
                    //yay spawn a new one
                    FallingMeteor f = InactiveMeteors [0];
                    InactiveMeteors.RemoveAt(0);
                    ActiveMeteors.Add(f);
                    f.Activate();
                }
            }
                        #endif

            if (Player.Local == null || !Player.Local.HasSpawned || !GameManager.Is(FGameState.InGame))
            {
                return;
            }

            if (GameWorld.Get.CurrentBiome.OuterSpace)
            {
                return;
            }

            if (WorldClock.IsDay)
            {
                mMeteorsFallenTonight = 0;
                mCheckedTonight       = false;
                mCheckMeteors++;
                if (mCheckMeteors > 30)
                {
                    mCheckMeteors = 0;

                    if (mMeteorsFallenToday < Globals.MaxMeteorsPerDay)
                    {
                        if (InactiveMeteors.Count > 0 && UnityEngine.Random.value < Globals.MeteorSpawnProbabilityDaytime && WorldClock.AdjustedRealTime > mLastMeteorSpawnTime + Globals.MeteorMinimumSpawnTime)
                        {
                            //yay spawn a new one
                            FallingMeteor f = InactiveMeteors [0];
                            InactiveMeteors.RemoveAt(0);
                            ActiveMeteors.Add(f);
                            f.Activate();
                            mMeteorsFallenToday++;
                            mLastMeteorSpawnTime = WorldClock.AdjustedRealTime;
                        }
                    }

                    if (ActiveMeteors.Count > 0)
                    {
                        for (int i = ActiveMeteors.LastIndex(); i >= 0; i--)
                        {
                            //remove any that have been killed
                            FallingMeteor f = ActiveMeteors [i];
                            if (f.IsDepleted)
                            {
                                InactiveMeteors.Add(f);
                                ActiveMeteors.RemoveAt(i);
                            }
                        }
                    }
                }
                return;
            }
            else
            {
                mMeteorsFallenToday = 0;

                if (!mCheckedTonight)
                {
                    mCheckedTonight = true;
                    if (Globals.OscillateMeteorSpawnAmount)
                    {
                        float period = (float)((WorldClock.AdjustedRealTime % Globals.MeteorSpawnOscillateDuration) / Globals.MeteorSpawnOscillateDuration);
                        AdjustedMaxMeteorsPerNight = Mathf.Clamp(Mathf.CeilToInt(Mathf.Sin(period) * Globals.MaxMeteorsPerNight), Globals.MinMeteorsPerNight, Globals.MaxMeteorsPerNight);
                    }
                    else
                    {
                        AdjustedMaxMeteorsPerNight = Globals.MaxMeteorsPerNight;
                    }
                }

                mCheckMeteors++;
                if (mCheckMeteors > 30)
                {
                    mCheckMeteors = 0;
                    if (mMeteorsFallenTonight < Globals.MaxMeteorsPerNight)
                    {
                        if (InactiveMeteors.Count > 0 && UnityEngine.Random.value < Globals.MeteorSpawnProbability && WorldClock.AdjustedRealTime > mLastMeteorSpawnTime + Globals.MeteorMinimumSpawnTime)
                        {
                            //yay spawn a new one
                            FallingMeteor f = InactiveMeteors [0];
                            InactiveMeteors.RemoveAt(0);
                            ActiveMeteors.Add(f);
                            f.Activate();
                            mMeteorsFallenTonight++;
                            mLastMeteorSpawnTime = WorldClock.AdjustedRealTime;
                            OnMeteorSpawned.SafeInvoke();
                        }
                    }

                    for (int i = ActiveMeteors.LastIndex(); i >= 0; i--)
                    {
                        //remove any that have been killed
                        FallingMeteor f = ActiveMeteors [i];
                        if (f.IsDepleted)
                        {
                            InactiveMeteors.Add(f);
                            ActiveMeteors.RemoveAt(i);
                            if (f.SpawnMeteor)
                            {
                                WorldChunk p = GameWorld.Get.PrimaryChunk;
                                f.transform.parent             = p.AboveGroundGroup.tr;
                                mActiveMeteorPosition.Position = f.transform.localPosition;
                                WorldItem newMeteorWorldItem = null;
                                WorldItems.CloneWorldItem("Crystals", "Falling Meteor", mActiveMeteorPosition, false, p.AboveGroundGroup, out newMeteorWorldItem);
                                newMeteorWorldItem.Initialize();
                                newMeteorWorldItem.ActiveState       = WIActiveState.Active;
                                newMeteorWorldItem.ActiveStateLocked = true;
                                MeteorsSpawned.Add(newMeteorWorldItem.Get <Meteor> ());
                                //get rid of dead meteors to make it easier on orbs
                                for (int j = MeteorsSpawned.LastIndex(); j >= 0; j--)
                                {
                                    if (MeteorsSpawned [j] == null || MeteorsSpawned [j].IsDestroyed)
                                    {
                                        MeteorsSpawned.RemoveAt(j);
                                    }
                                }

                                OnMeteorSpawned.SafeInvoke();
                            }
                        }
                    }
                }
            }
        }