예제 #1
0
        protected IEnumerator AddToReceptaclePivotOverTime(WorldItem potentialOccupant, ReceptaclePivot pivotInFocus)
        {
            //remove it from any situation that could cause a c**k-up
            worlditem.Group.AddChildItem(potentialOccupant);
            potentialOccupant.SetMode(WIMode.World);
            //this will put it into the world and un-equip it etc
            //wait for that to happen
            yield return(null);

            WIStack      pivotStack = worlditem.StackContainer.StackList [pivotInFocus.State.Index];
            WIStackError error      = WIStackError.None;

            //do not auto convert to stack item
            if (!Stacks.Push.Item(pivotStack, potentialOccupant, StackPushMode.Manual, ref error))
            {
                Debug.Log("Couldn't push item into group because " + error.ToString());
                yield break;
            }
            //wait again for the worlditem to get situated
            yield return(null);

            potentialOccupant.OnRemoveFromStack += Refresh;
            potentialOccupant.OnModeChange      += Refresh;
            potentialOccupant.tr.parent          = pivotInFocus.tr;
            //this will move it into the recepticle position
            pivotInFocus.Refresh();
            yield return(null);

            OnItemPlacedInReceptacle.SafeInvoke();
            mAddingToReceptaclePivot = false;
        }
예제 #2
0
        public void Refresh()
        {
            if (mRefreshing)
            {
                return;
            }

            mRefreshing = true;
            if (IsOccupied)
            {
                //check to see if we're still actually occupied
                if (Occupant != mParentStack.TopItem)
                {
                    mOccupant = null;
                }
                else
                {
                    //lock the transform to make sure it won't be moved by its group
                    LockOccupant(true);
                    Occupant.ParentPivot = this;
                    Occupant.SetMode(WIMode.Placed);
                    Occupant.LastActiveDistanceToPlayer = Occupant.ActiveRadius * 0.5f;
                    Occupant.ActiveStateLocked          = false;
                    Occupant.ActiveState = WIActiveState.Active;
                    Occupant.worlditem.tr.localPosition = Occupant.worlditem.BasePivotOffset;
                    Occupant.worlditem.tr.localRotation = Quaternion.identity;

                    mBounds.center = Occupant.Position;
                    mBounds.size   = Vector3.one * 0.001f;

                    for (int i = 0; i < Occupant.Renderers.Count; i++)
                    {
                        if (Occupant.Renderers [i].enabled)
                        {
                            mBounds.Encapsulate(Occupant.Renderers [i].bounds);
                        }
                    }

                    if (OccupantDoppleganger != null)
                    {
                        GameObject.Destroy(OccupantDoppleganger);
                    }
                }
            }
            else if (OccupantDoppleganger != null)
            {
                GameObject.Destroy(OccupantDoppleganger);
                mBounds.center = tr.position + Vector3.up * 0.05f;
                mBounds.size   = Vector3.one * 0.1f;
            }

            mRefreshing = false;
        }
예제 #3
0
        protected IEnumerator Equip()
        {
            if (Holstered)
            {
                Debug.Log("Holstered");
                yield break;
            }

            ToolState = PlayerToolState.Equipping;
            //set equipped mode
            worlditem.SetMode(WIMode.Equipped);
            //clear all actions
            mActions.Clear();
            //see if the worlditem is a weapon
            //if it is, find a projectile for it
            Weapon     weapon     = null;
            Equippable equippable = null;

            if (worlditem.Is <Equippable> (out equippable))              //tell equippable that we're equipping
            {
                equippable.EquipStart();
            }

            //refresh our dopplegangers
            //we do this BEFORE playing the generic equip animation
            //so it actually has something to show
            RefreshToolDoppleganger(true);
            if (equippable != null)
            {
                equippable.EquipFinish();
            }

            yield return(StartCoroutine(PlayAnimation("ToolGenericEquip")));

            ToolState = PlayerToolState.Equipped;
            yield break;
        }
예제 #4
0
        public void OnPowerSourceRemoved()
        {
            if (mSpawnedDeactivatedOrb)
            {
                return;
            }
            //this will swap it out for an item that can be carried
            mSpawnedDeactivatedOrb = true;
            WorldItem  deactivatedOrb = null;
            STransform orbSpawnPoint  = new STransform(LuminiteGemPivot.position, LuminiteGemPivot.rotation.eulerAngles, Vector3.zero);

            if (WorldItems.CloneWorldItem(DeactivatedOrbGenericWorldItem, orbSpawnPoint, false, WIGroups.Get.World, out deactivatedOrb))
            {
                deactivatedOrb.Props.Local.Mode = WIMode.World;
                deactivatedOrb.Initialize();
                deactivatedOrb.SetMode(WIMode.World);
                worlditem.RemoveFromGame();
            }
        }
예제 #5
0
 public void OnDie()
 {
     PowerSource.HasPower = false;
     if (PowerSource.HasPowerSource)
     {
         //drop the crystal into the world
         WorldItem  droppedGem    = null;
         STransform gemSpawnPoint = new STransform(LuminiteGemPivot.position, LuminiteGemPivot.rotation.eulerAngles, Vector3.zero);
         if (WorldItems.CloneWorldItem(PowerSource.PowerSourceDopplegangerProps, gemSpawnPoint, false, WIGroups.Get.World, out droppedGem))
         {
             droppedGem.Props.Local.Mode = WIMode.World;
             droppedGem.Initialize();
             droppedGem.SetMode(WIMode.World);
             FXManager.Get.SpawnFX(droppedGem.tr, "DrawAttentionToItem");
         }
         FXManager.Get.SpawnExplosion(ExplosionType.Simple, worlditem.Position, 1f, 1f, 0.1f, 0.5f, OrbExplosionDamage);
     }
     OrbSpeak(OrbSpeakUnit.UnitExpiring, worlditem.tr);
 }
예제 #6
0
        public void OnPlayerUseWorldItemSecondary(object secondaryResult)
        {
            WIListResult dialogResult = secondaryResult as WIListResult;

            switch (dialogResult.SecondaryResult)
            {
            case "Shear":
                State.LastTimeSheared = WorldClock.AdjustedRealTime;
                //spawn a random number of wool items
                //make it pop off the chest body part, upwards
                WorldItem shearedWorldItem = null;
                BodyPart  chestBodyPart    = null;
                creature.Body.GetBodyPart(BodyPartType.Chest, out chestBodyPart);
                Bounds        colliderBounds = chestBodyPart.PartCollider.bounds;
                Vector3       popPosition;
                Vector3       popDirection;
                System.Random random          = new System.Random(Profile.Get.CurrentGame.Seed);
                int           numShearedItems = random.Next(MinShearedItems, MaxShearedItems);
                Debug.Log("Shearing " + numShearedItems.ToString() + " Items in " + name);
                for (int i = 0; i < numShearedItems; i++)
                {
                    popPosition = (UnityEngine.Random.onUnitSphere * 5f) + chestBodyPart.tr.position;
                    popPosition = chestBodyPart.PartCollider.ClosestPointOnBounds(popPosition);
                    //give it a push in a direction away from the body
                    popDirection = Vector3.Normalize(chestBodyPart.tr.position - popPosition);

                    if (WorldItems.CloneWorldItem(ShearedItem, STransform.zero, false, WIGroups.GetCurrent(), out shearedWorldItem))
                    {
                        shearedWorldItem.Initialize();
                        shearedWorldItem.SetMode(WIMode.World);
                        shearedWorldItem.tr.position = popPosition;
                        shearedWorldItem.ApplyForce(popDirection, popPosition);
                    }
                    //let them all fall away
                }
                //the creature freaks out but doesn't actually take damage
                creature.OnTakeDamage();
                break;

            default:
                break;
            }
        }
예제 #7
0
        public void OnDie()
        {
            switch (worlditem.State)
            {
            case "Mined":
                Debug.Log("DIED in luminite node with state mined");
                worlditem.Get <Damageable> ().ResetDamage();
                State.TimeMined = WorldClock.AdjustedRealTime;
                break;

            default:
                Debug.Log("DIED in luminite node with state " + worlditem.State);
                worlditem.Get <Damageable> ().ResetDamage();
                //set luminite type to mined raw, then get a stack item for the player
                //add that to player inventory
                WorldItem        rawLuminite     = null;
                GenericWorldItem rawLuminiteItem = RawLuminiteLight;
                if (worlditem.State == "Dark")
                {
                    rawLuminiteItem = RawLuminiteDark;
                }
                if (WorldItems.CloneWorldItem(
                        rawLuminiteItem,
                        new STransform(worlditem.tr),
                        false,
                        worlditem.Group,
                        out rawLuminite))
                {
                    //this will drop to the players' feet
                    rawLuminite.Props.Local.FreezeOnStartup = false;
                    rawLuminite.Initialize();
                    rawLuminite.SetMode(WIMode.World);
                    rawLuminite.GetComponent <Rigidbody>().AddForce(worlditem.tr.up * 0.25f);
                }
                State.TimeMined       = WorldClock.AdjustedRealTime;
                State.AbsorbedDarkRot = 0f;
                worlditem.State       = "Mined";
                break;
            }

            Debug.Log("State is now " + worlditem.State);
        }
예제 #8
0
        public void OnDie()
        {
            Debug.Log("OnDie called in drop items on die");
            if (gSpawnPointTransform == null)
            {
                gSpawnPointTransform = new STransform();
            }

            string categoryName = WICategoryName;

            if (!string.IsNullOrEmpty(WICategoryNameBurned))
            {
                if (worlditem.Get <Damageable> ().State.LastDamageSource == "Fire")
                {
                    categoryName = WICategoryNameBurned;
                }
            }

            if (DropEveryItemInCategory)
            {
                WICategory category = null;
                if (WorldItems.Get.Category(categoryName, out category))
                {
                    for (int i = 0; i < category.GenericWorldItems.Count; i++)
                    {
                        //create one for each instance
                        for (int j = 0; j < category.GenericWorldItems [i].InstanceWeight; j++)
                        {
                            gSpawnPointTransform.Position   = worlditem.tr.TransformPoint(SpawnPoints [i % SpawnPoints.Count]);
                            gSpawnPointTransform.Rotation.x = Random.Range(0f, 360f);
                            gSpawnPointTransform.Rotation.y = Random.Range(0f, 360f);
                            gSpawnPointTransform.Rotation.z = Random.Range(0f, 360f);
                            if (WorldItems.CloneWorldItem(category.GenericWorldItems [i], gSpawnPointTransform, false, WIGroups.Get.World, out gDropItem))
                            {
                                gDropItem.Props.Local.Mode = WIMode.World;
                                gDropItem.Initialize();
                                gDropItem.SetMode(WIMode.World);

                                if (!string.IsNullOrEmpty(DropEffect))
                                {
                                    FXManager.Get.SpawnFX(gDropItem, DropEffect);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                //we prefer spawn points first
                if (SpawnPoints.Count > 0)
                {
                    for (int i = 0; i < SpawnPoints.Count; i++)
                    {
                        mSpawnPoint = SpawnPoints [i];
                        if (Random.value > RandomDropout)
                        {
                            if (WorldItems.CloneRandomFromCategory(categoryName, WIGroups.Get.World, out gDropItem))                                    ////Debug.Log ("Cloning item!");
                            {
                                gDropItem.Props.Local.Transform.Position = worlditem.tr.TransformPoint(mSpawnPoint);
                                //Debug.Log ("Worlditem at position " + worlditem.tr.position + " dropping item " + gDropItem.Props.Local.Transform.Position.ToString () + " from spawn point " + mSpawnPoint.ToString());
                                gDropItem.Props.Local.Transform.Rotation.x = Random.Range(0f, 360f);
                                gDropItem.Props.Local.Transform.Rotation.y = Random.Range(0f, 360f);
                                gDropItem.Props.Local.Transform.Rotation.z = Random.Range(0f, 360f);
                                gDropItem.Props.Local.FreezeOnStartup      = false;
                                gDropItem.Props.Local.Mode = WIMode.World;
                                gDropItem.Initialize();
                                gDropItem.SetMode(WIMode.World);
                                if (!string.IsNullOrEmpty(DropEffect))
                                {
                                    FXManager.Get.SpawnFX(gDropItem, DropEffect);
                                }
                            }
                        }
                    }
                }
                else
                {
                    //if no spawn points exist, spawn stuff using mesh vertices
                    //System.Random random = new System.Random (Profile.Get.CurrentGame.Seed);
                    int      numToSpawn = UnityEngine.Random.Range(MinRandomItems, MaxRandomItems);                //random.Next (MinRandomItems, MaxRandomItems);
                    Renderer r          = null;
                    if (worlditem.HasStates)
                    {
                        r = worlditem.States.CurrentState.StateRenderer;
                    }
                    else
                    {
                        //just get the first renderer
                        r = worlditem.Renderers [0];
                    }
                    //TODO make this more safe?
                    Mesh      sharedMesh = r.GetComponent <MeshFilter> ().sharedMesh;
                    Vector3[] vertices   = sharedMesh.vertices;
                    //Debug.Log ("Spawning from " + vertices.Length.ToString () + " vertices");
                    for (int i = 0; i < numToSpawn; i++)
                    {
                        if (WorldItems.CloneRandomFromCategory(categoryName, WIGroups.Get.World, out gDropItem))
                        {
                            gDropItem.Props.Local.Transform.Position = worlditem.tr.TransformPoint(vertices [UnityEngine.Random.Range(0, vertices.Length)]);
                            //Debug.Log ("Worlditem at position " + worlditem.tr.position + " dropping item " + gDropItem.Props.Local.Transform.Position.ToString () + " from mesh spawn point " + mSpawnPoint.ToString ());
                            gDropItem.Props.Local.Transform.Rotation.x = Random.Range(0f, 360f);
                            gDropItem.Props.Local.Transform.Rotation.y = Random.Range(0f, 360f);
                            gDropItem.Props.Local.Transform.Rotation.z = Random.Range(0f, 360f);
                            gDropItem.Props.Local.FreezeOnStartup      = false;
                            gDropItem.Props.Local.Mode = WIMode.World;
                            gDropItem.Initialize();
                            gDropItem.SetMode(WIMode.World);

                            if (!string.IsNullOrEmpty(DropEffect))
                            {
                                FXManager.Get.SpawnFX(gDropItem, DropEffect);
                            }
                        }
                        else
                        {
                            Debug.Log("Couldn't clone item from category " + categoryName);
                        }
                    }
                }
            }
            Finish();
        }
예제 #9
0
        public void OnClickSquare()
        {
            Debug.Log("Clicking result square");
            WIStackError error = WIStackError.None;

            if (ReadyForRetrieval)
            {
                Debug.Log("Is ready for retrieval");
                while (NumItemsCrafted > 0)
                {
                    StackItem craftedItem = CraftedItemTemplate.ToStackItem();
                    craftedItem.Group = WIGroups.Get.Player;
                    if (craftedItem.CanEnterInventory)
                    {
                        if (Player.Local.Inventory.AddItems(craftedItem, ref error))
                        {
                            Debug.Log("Added item to inventory");
                            NumItemsCrafted--;
                        }
                        else
                        {
                            Debug.Log("Couldn't add to inventory, what now?");
                            break;
                        }
                    }
                    else
                    {
                        Debug.Log("We have to carry the item");
                        if (Player.Local.ItemPlacement.IsCarryingSomething)
                        {
                            Player.Local.ItemPlacement.PlaceOrDropCarriedItem();
                        }
                        //turn it into a worlditem and have the player carry it
                        WorldItem craftedWorldItem = null;
                        if (WorldItems.CloneFromStackItem(craftedItem, WIGroups.GetCurrent(), out craftedWorldItem))
                        {
                            craftedWorldItem.Props.Local.CraftedByPlayer = true;
                            craftedWorldItem.Initialize();
                            craftedWorldItem.ActiveState = WIActiveState.Active;
                            craftedWorldItem.Props.Local.FreezeOnStartup = false;
                            craftedWorldItem.tr.rotation = Quaternion.identity;
                            craftedWorldItem.SetMode(WIMode.World);
                            craftedWorldItem.tr.position = Player.Local.ItemPlacement.GrabberIdealPosition;
                            craftedWorldItem.LastActiveDistanceToPlayer = 0f;
                            //if we have an interface open, close it now
                            GUIInventoryInterface.Get.Minimize();
                            //then force the player to carry the item
                            if (Player.Local.ItemPlacement.ItemCarry(craftedWorldItem, true))
                            {
                                NumItemsCrafted--;
                            }
                            else
                            {
                                GUIManager.PostWarning("You have to drop what you're carrying first");
                            }
                            //set placement mode to true immediately
                            Player.Local.ItemPlacement.PlacementModeEnabled = true;
                        }
                        break;
                    }
                }
            }
            else
            {
                Debug.Log("Not ready for retrieval");
            }

            RefreshRequest();
        }
예제 #10
0
        protected IEnumerator Equip()
        {
            ToolState = PlayerToolState.Equipping;
            //set equipped mode
            worlditem.SetMode(WIMode.Equipped);
            //clear all actions
            mActions.Clear();
            LaunchForce = 0f;
            //see if the worlditem is a weapon
            //if it is, find a projectile for it
            if (worlditem.Is <Equippable>(out mEquippable))                                      //tell equippable that we're equipping
            {
                mEquippable.EquipStart();
                if (worlditem.Is <Weapon>(out mWeapon))
                {
                    player.FPSMelee.CurrentWeapon = mWeapon;
                    bool loadProjectile = false;
                    if (mWeapon.Style == PlayerToolStyle.ProjectileLaunch)
                    {
                        //first see if the projectile is compaitble
                        if (HasProjectile)
                        {
                            if (!Weapon.CanLaunch(mWeapon, ProjectileObject))
                            {
                                //if we can't launch it, load it
                                loadProjectile = true;
                            }
                        }
                        else
                        {
                            //if we don't have one, find it and load it
                            loadProjectile = true;
                        }
                    }
                    if (loadProjectile)
                    {
                        //load the projectile before we create the doppleganger
                        //don't play animations because we're already playing the equipping animation
                        yield return(StartCoroutine(FindAndLoadProjectile(mEquippable, mWeapon, false)));
                    }
                }
            }

            //refresh our dopplegangers
            //we do this BEFORE playing the generic equip animation
            //so it actually has something to show
            RefreshToolDoppleganger(true);
            if (mEquippable != null)
            {
                mEquippable.EquipFinish();
            }

            yield return(StartCoroutine(PlayAnimation("ToolGenericEquip")));

            if (mEquippable != null)
            {
                mEquippable.FullyEquipped = true;
            }

            ToolState = PlayerToolState.Equipped;
            yield break;
        }