Пример #1
0
    public override void ExecuteAction(int _actionIdx, ItemInventoryData _data, bool _bReleased, PlayerActionsLocal _playerActions)
    {
        if (Actions[_actionIdx] == null)
        {
            return;
        }

        if (!_bReleased)
        {
            return;
        }

        EntityAlive ea = _data.holdingEntity;

        if (_actionIdx == 0)
        {
            _itemAction_TE_ObjectManipulator.ExecuteAction(_data.actionData[_actionIdx], _bReleased);
        }
        else if (_actionIdx == 1 && ea is EntityPlayerLocal)
        {
            _itemAction_TE_ObjectManipulator.ToggleActive(_data.actionData[_actionIdx]);
        }
        else
        {
            // I didn't see anywhere in the code where this was possible, but maybe in the future.  A20??
            Log.Out($"TE_ObjectManipulatorItem::ExecuteAction index: {_actionIdx} pressed.");
        }
    }
Пример #2
0
    /// <summary>
    /// Checks if we have stored a reference to the Animator component... if not it gets one and returns true if all is ok
    /// The animator will control the different fishing rod states
    /// </summary>
    /// <param name="_data">Item inventory data reference</param>
    /// <returns>Returns true if the reference to the Animator component is valid</returns>
    private bool CheckAnimatorReference(ItemInventoryData _data)
    {
        // Check if the reference to the LineRenderer component is null
        if (!animator)
        {
            // Debug
            //DisplayChatAreaText("Warning: animator reference is null... getting reference now.");

            // Get and store a reference to the animator component
            animator = _data.model.GetComponentInChildren <Animator>();

            // Check if we were not able to get a reference to the animator component
            if (!animator)
            {
                // Debug
                //DisplayChatAreaText("Error: animator component not found!");
                return(false);
            }
            else
            {
                // Return true as we now have a reference to the animator component
                //DisplayChatAreaText("Found animator");
                return(true);
            }
        }
        else
        {
            // Return true as we already have a reference to the LineRenderer component
            return(true);
        }
    }
Пример #3
0
    // -----------------------------------------------------------------------------------------------



    public override void StartHolding(ItemInventoryData _data, Transform _modelTransform)
    {
        base.StartHolding(_data, _modelTransform);
        animator      = null;
        epLocalPlayer = null;
        ResetFishing();
    }
Пример #4
0
 public static void Prefix(Inventory __instance, ref int ___m_HoldingItemIdx, ref int ___m_LastDrawnHoldingItemIndex, ItemInventoryData[] ___slots, ItemInventoryData ___emptyItem)
 {
     for (int i = 0; i < ___slots.Length; i++)
     {
         ___slots[i] = ___emptyItem;
     }
     ___slots            = new ItemInventoryData[11];
     __instance.models   = new Transform[11];
     ___m_HoldingItemIdx = 0;
 }
Пример #5
0
    /// <summary>
    /// Called when the player stops holding the ACW item
    /// </summary>
    /// <param name="_data">A reference to the items inventory data.</param>
    /// <param name="_modelTransform">A reference to the models transform.</param>
    public override void StopHolding(ItemInventoryData _data, Transform _modelTransform)
    {
        // Call base code
        base.StopHolding(_data, _modelTransform);

        OnActivateItemGameObjectReference component = _modelTransform.GetComponent <OnActivateItemGameObjectReference>();

        if (component != null && component.IsActivated())
        {
            component.ActivateItem(false);
        }
    }
Пример #6
0
    /// <summary>
    /// Choose a random loot type.
    /// </summary>
    private LootType Choose(ItemInventoryData _data)
    {
        // quality modifier - it changes the chance to get anything by reducing the max range
        int    auxMaxProb   = MaxProbability;
        double probModifier = 1;

        if (_data.itemValue.HasQuality)
        {
            if (_data.itemValue.Quality < 100)
            {
                probModifier = 1;
            }
            else if (_data.itemValue.Quality >= 100 && _data.itemValue.Quality < 250)
            {
                probModifier = 0.85;
            }
            else if (_data.itemValue.Quality >= 250 && _data.itemValue.Quality < 550)
            {
                probModifier = 0.65;
            }
            else
            {
                probModifier = 0.45;
            }
        }
        auxMaxProb = Convert.ToInt32(Math.Floor(MaxProbability * probModifier));
        System.Random _rnd        = new System.Random((int)(DateTime.Now.Ticks & 0x7FFFFFFF));
        LootType      lootType    = 0; // start at first one
        int           randomValue = _rnd.Next(auxMaxProb);

        if (CalculateDistribution())
        {
            //DisplayChatAreaText(randomValue.ToString());
            if (randomValue >= 1000)
            {
                randomValue = 999;
            }
            while (_lootDist[(int)lootType] <= randomValue)
            {
                lootType++; // next loot type
            }
        }
        else
        {
            lootType = LootType.nothing;
        }
        return(lootType);
    }
Пример #7
0
    private IEnumerator EB(ItemInventoryData itemInventoryData, int idx)
    {
        yield return(new WaitForEndOfFrame());

        yield return(new WaitForEndOfFrame());

        yield return(new WaitForEndOfFrame());

        ItemStack itemStack = itemInventoryData.holdingEntity.inventory.GetItem(idx).Clone();

        if (itemStack.count > 0)
        {
            itemStack.count--;
        }

        itemInventoryData.holdingEntity.inventory.SetItem(idx, itemStack);
        itemInventoryData.holdingEntity.PlayOneShot((this.soundStart == null) ? "placeblock" : this.soundStart);
        yield break;
    }
Пример #8
0
    /// <summary>
    /// Called when the player stops holding the ACW item
    /// </summary>
    /// <param name="_data">A reference to the items inventory data.</param>
    /// <param name="_modelTransform">A reference to the models transform.</param>
    public override void StopHolding(ItemInventoryData _data, Transform _modelTransform)
    {
        // Debug
        //DisplayChatAreaText("StopHolding");
        // Reset flags
        ResetFishing();

        // Call base code
        base.StopHolding(_data, _modelTransform);

        // Check if the model transform is null
        if (_modelTransform == null)
        {
            return;
        }
        OnActivateItemGameObjectReference component = _modelTransform.GetComponent <OnActivateItemGameObjectReference>();

        if (component != null && component.IsActivated())
        {
            component.ActivateItem(false);
        }
    }
Пример #9
0
 public override ItemActionData CreateModifierData(ItemInventoryData _invData, int _indexInEntityOfAction)
 {
     return(new ItemActionSpawnEntity.ItemActionDataSpawnEntity(_invData, _indexInEntityOfAction));
 }
Пример #10
0
        /**
         * CTOR
         */

        public ItemActionDataSpawnEntity(ItemInventoryData _invData, int _indexInEntityOfAction) : base(_invData, _indexInEntityOfAction)
        {
        }
Пример #11
0
    /**
     * Executes the action data.
     */

    public override void ExecuteAction(ItemActionData _actionData, bool _bReleased)
    {
        ItemActionSpawnEntity.ItemActionDataSpawnEntity itemActionDataSpawnEntity = (ItemActionSpawnEntity.ItemActionDataSpawnEntity)_actionData;
        if (!(_actionData.invData.holdingEntity is EntityPlayerLocal))
        {
            return;
        }
        if (!_bReleased)
        {
            return;
        }
        if (Time.time - _actionData.lastUseTime < this.Delay)
        {
            return;
        }
        if (Time.time - _actionData.lastUseTime < Constants.cBuildIntervall)
        {
            return;
        }
        if (!itemActionDataSpawnEntity.ValidPosition)
        {
            return;
        }
        ItemInventoryData invData = _actionData.invData;

        if (this.entityId < 0)
        {
            foreach (KeyValuePair <int, EntityClass> keyValuePair in EntityClass.list.Dict)
            {
                if (keyValuePair.Value.entityClassName == this.entityToSpawn)
                {
                    this.entityId = keyValuePair.Key;
                    break;
                }
            }
            if (this.entityId == 0)
            {
                return;
            }
        }
        ItemValue holdingItemItemValue = invData.holdingEntity.inventory.holdingItemItemValue;

        if (!SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer)
        {
            SingletonMonoBehaviour <ConnectionManager> .Instance.SendToServer(NetPackageManager.GetPackage <NetPackageVehicleSpawn>().Setup(this.entityId, itemActionDataSpawnEntity.Position, new Vector3(0f, invData.holdingEntity.rotation.y + 90f, 0f), holdingItemItemValue.Clone(), invData.holdingEntity.entityId), true);
        }
        else
        {
            Entity entity = EntityFactory.CreateEntity(this.entityId, itemActionDataSpawnEntity.Position + Vector3.up * 0.25f, new Vector3(0f, _actionData.invData.holdingEntity.rotation.y + 90f, 0f));
            entity.SetSpawnerSource(EnumSpawnerSource.StaticSpawner);
            if (entity as EntityAlive != null)
            {
                (entity as EntityAlive).factionId       = itemActionDataSpawnEntity.invData.holdingEntity.factionId;
                (entity as EntityAlive).belongsPlayerId = itemActionDataSpawnEntity.invData.holdingEntity.entityId;
                (entity as EntityAlive).factionRank     = (byte)(itemActionDataSpawnEntity.invData.holdingEntity.factionRank - 1);
            }
            GameManager.Instance.World.SpawnEntityInWorld(entity);
        }
        if (itemActionDataSpawnEntity.EntityPreviewT != null && itemActionDataSpawnEntity.invData.holdingEntity is EntityPlayerLocal)
        {
            UnityEngine.Object.Destroy(itemActionDataSpawnEntity.EntityPreviewT.gameObject);
        }
        invData.holdingEntity.RightArmAnimationUse = true;
        (invData.holdingEntity as EntityPlayerLocal).DropTimeDelay = 0.5f;
        invData.holdingEntity.inventory.DecHoldingItem(1);
        invData.holdingEntity.PlayOneShot((this.soundStart != null) ? this.soundStart : "placeblock", false);
    }
Пример #12
0
    /// <summary>
    /// Called when holding the fishing rod
    /// </summary>
    /// <param name="_data">A reference to the items inventory data.</param>
    public override void OnHoldingUpdate(ItemInventoryData _data)
    {
        // Debug
        //DisplayChatAreaText("OnHoldingUpdate");

        // Base code - no need to run it for the rod.
        //base.OnHoldingUpdate(_data);

        // Don't run this code if remote entity
        if (_data.holdingEntity.isEntityRemote)
        {
            return;
        }
        // check if the player is aiming at water
        // Check reference to local player
        if (!epLocalPlayer)
        {
            // Get and store a reference to the local player
            epLocalPlayer = GameManager.Instance.World.GetLocalPlayer();

            // Debug
            //DisplayChatAreaText("Reference to local player stored.");
        }
        try
        {
            if (!CheckWaterInRange())
            {
                if (boolAimingWater)
                {
                    boolAimingWater = false;
                    DisplayToolTipText("Man... I can't fish here...");
                    ResetFishing();
                }
                return;
            }
            else
            {
                if (!boolAimingWater)
                {
                    if (CheckAnimatorReference(_data))
                    {
                        ResetFishing();
                        if (epLocalPlayer)
                        {
                            MultiBuffClassAction multiBuffClassAction = MultiBuffClassAction.NewAction("fishingWater");
                            multiBuffClassAction.Execute(epLocalPlayer.entityId, (EntityAlive)epLocalPlayer, false,
                                                         EnumBodyPartHit.None, (string)null);
                        }
                    }
                    boolAimingWater = true;
                    DisplayToolTipText("Yea... This looks like a nice spot.");
                }
            }
        }
        catch (Exception)
        {
            DisplayChatAreaText("DEBUG: Oops something went wrong with the fishing mod.");
        }
        // Check if the player is already fishing
        if (true)
        {
            #region Hook event expired;

            if (boolFishHooked && boolAimingWater)
            {
                if (DateTime.Now > dteEndHook)
                {
                    animator.SetTrigger("stopFishing");
                    DisplayToolTipText("Shit... Whatever it was... It's gone!");
                    boolFishHooked = false;
                    dteNextAction  = DateTime.Now.AddSeconds(0.5);
                }
            }

            #endregion ;

            #region fish event expired;

            if (boolFishing && boolAimingWater)
            {
                if (DateTime.Now > dteEndFish)
                {
                    animator.SetTrigger("stopFishing");
                    if (intLoot != LootType.nothing)
                    {
                        DisplayToolTipText("Great... It's gone... Let's be faster next time, shall we?");
                    }
                    else
                    {
                        DisplayToolTipText("Oh well... Shall we try again?");
                    }
                    boolFishing   = false;
                    intLoot       = LootType.nothing;
                    dteNextAction = DateTime.Now.AddSeconds(0.5);
                }
            }

            #endregion ;

            #region Wait for bait;

            if (!boolFishHooked && !boolRodBaited && !boolBaitWait && !boolFishing && boolAimingWater)
            {
                if (DateTime.Now > dteNextAction)
                {
                    if (animator)
                    {
                        animator.SetTrigger("waitBait");
                        boolBaitWait  = true;
                        dteNextAction = DateTime.Now.AddSeconds(0.5);
                    }
                }
            }

            #endregion ;

            #region Bait rod;

            // bait rod if not already baited, no hook event present, and no loot to get.
            if (Input.GetKey(KeyCode.R) && boolAimingWater && !boolRodBaited && !boolFishHooked && boolBaitWait)
            {
                if (DateTime.Now > dteNextAction)
                {
                    ItemValue earthworm = ItemClass.GetItem("earthworm", false);
                    int       numWorms  = epLocalPlayer.bag.GetItemCount(earthworm);
                    if (numWorms >= 1)
                    {
                        bool itemGood = true;
                        // cause decay
                        if (_data.itemValue.MaxUseTimes > 0)
                        {
                            ItemValue itemValue = _data.itemValue;
                            itemValue.UseTimes += AttributeBase.GetVal <AttributeDegradationRate>(_data.itemValue, 1);
                            _data.itemValue     = itemValue;
                            if (_data.itemValue.MaxUseTimes > 0 &&
                                _data.itemValue.UseTimes >= _data.itemValue.MaxUseTimes ||
                                _data.itemValue.UseTimes == 0 && _data.itemValue.MaxUseTimes == 0)
                            {
                                // cane is broken
                                itemGood = false;
                                DisplayToolTipText("Hmm, i think i've been fishing too much... Need to fix this...");
                            }
                        }
                        if (itemGood)
                        {
                            epLocalPlayer.bag.DecItem(earthworm, 1);
                            if (animator)
                            {
                                animator.SetTrigger("stopFishing");
                                DisplayToolTipText("Alright! Got this thing baited, let's see what I get...");
                                boolRodBaited = true;
                                boolBaitWait  = false;
                            }
                            dteNextAction = DateTime.Now.AddSeconds(2);
                        }
                        else
                        {
                            dteNextAction = DateTime.Now.AddSeconds(0.5);
                        }
                    }
                    else
                    {
                        DisplayToolTipText("You don't have enough earth worms...");
                        dteNextAction = DateTime.Now.AddSeconds(0.5);
                    }
                }
            }

            #endregion ;

            #region Hook event;

            // if baited and not fish hooked...
            if (boolRodBaited && !boolFishHooked && boolAimingWater && !boolFishing)
            {
                // randomly does hook warning -> it lasts 2 seconds.
                if (DateTime.Now > dteNextAction)
                {
                    System.Random r       = new System.Random();
                    int           hookNow = r.Next(1, 101);
                    if (hookNow <= 8)
                    {
                        if (animator)
                        {
                            this.boolFishHooked = true;
                            boolRodBaited       = false; // always looses the bait here.
                            // decides what the loot will be here, to determine what time the player will have to react
                            // the rarer the loot the less time he has
                            intLoot = Choose(_data);
                            double timeToReact = numLootTypes - 2;
                            if (intLoot > 0 && intLoot != LootType.nothing)
                            {
                                timeToReact = timeToReact / intLoot.GetHashCode();
                            }
                            animator.SetTrigger("fishHook");
                            dteEndHook = DateTime.Now.AddSeconds(timeToReact);
                            //DisplayToolTipText("You've hooked something");
                            dteNextAction = DateTime.Now.AddSeconds(0.1);
                        }
                    }
                    else
                    {
                        // next possible bite will only be evaluated every one second
                        dteNextAction = DateTime.Now.AddSeconds(1);
                    }
                }
            }

            #endregion ;

            #region Hook Pull;

            // pulls the rod, decides what is the loot and waits 2 seconds...
            // if the player doesn't react, puff... Loot is gone!
            if (boolFishHooked && boolAimingWater)
            {
                if (Input.GetKey(KeyCode.Keypad1) || Input.GetKey(KeyCode.Mouse0) || Input.GetMouseButton(0))
                {
                    if (DateTime.Now > dteNextAction)
                    {
                        boolFishHooked = false;
                        if (animator)
                        {
                            animator.SetTrigger("hookPull");
                            boolFishing = true;
                            // see what was gotten, and show the proper animation
                            if (intLoot == LootType.nothing)
                            {
                                DisplayToolTipText("What the f**k? Nothing?");
                            }
                            else if (intLoot == LootType.head)
                            {
                                DisplayToolTipText("What... the... f... AAAAAAHHHHH!");
                                animator.SetTrigger("head");
                            }
                            else if (intLoot == LootType.trashBag)
                            {
                                DisplayToolTipText("YES! Got it! hmm... no? what?");
                                animator.SetTrigger("trash");
                            }
                            else if (intLoot == LootType.bigBass || intLoot == LootType.bigSalmon)
                            {
                                DisplayToolTipText("YES! That's a big one!");
                                animator.SetTrigger("bigFish");
                            }
                            else if (intLoot == LootType.salmon)
                            {
                                DisplayToolTipText("A salmon... Tasty!");
                                animator.SetTrigger("smallFish");
                            }
                            else if (intLoot == LootType.bass)
                            {
                                DisplayToolTipText("A nice looking bass fish!");
                                animator.SetTrigger("smallFish");
                            }
                            else
                            {
                                DisplayToolTipText("Better then nothing. Food is food!");
                                animator.SetTrigger("smallFish");
                            }
                            if (intLoot != LootType.nothing)
                            {
                                dteEndFish = DateTime.Now.AddSeconds(10); // 10 seconds to pick the fish up
                            }
                            else
                            {
                                dteEndFish = DateTime.Now.AddSeconds(0.5);
                            }
                        }
                        dteNextAction = DateTime.Now.AddSeconds(0.5);
                    }
                }
            }

            #endregion ;

            #region Get loot;

            // get's whatever is in the hook
            if (boolFishing && boolAimingWater)
            {
                if (Input.GetKey(KeyCode.Keypad2) || Input.GetKey(KeyCode.Mouse1) || Input.GetMouseButton(1))
                {
                    if (DateTime.Now > dteNextAction)
                    {
                        boolFishing = false;
                        if (intLoot != LootType.nothing)
                        {
                            //DisplayToolTipText("Got it... Shall we try again?");
                            //ItemValue lootItem = ItemClass.GetItem(intLoot.ToString());
                            ItemValue lootItem  = ItemClass.GetItem(intLoot.ToString(), false);
                            ItemStack lootStack = new ItemStack(lootItem, 1);
                            epLocalPlayer.bag.AddItem(lootStack);
                        }
                        //else DisplayToolTipText("Oh well... Shall we try again?");
                        ResetFishing();
                        dteNextAction = DateTime.Now.AddSeconds(0.5);
                    }
                }
            }

            #endregion ;
        }
    }
Пример #13
0
    /// <summary>
    /// Called when holding the fishing rod
    /// </summary>
    /// <param name="_data">A reference to the items inventory data.</param>
    public override void OnHoldingUpdate(ItemInventoryData _data)
    {
        // Debug
        //DisplayChatAreaText("OnHoldingUpdate");

        // Base code - no need to run it for the rod.
        //base.OnHoldingUpdate(_data);

        // Don't run this code if remote entity
        if (_data.holdingEntity.isEntityRemote)
        {
            return;
        }
        // check if the player is aiming at water
        // Check reference to local player
        if (!epLocalPlayer)
        {
            // Get and store a reference to the local player
            epLocalPlayer = GameManager.Instance.World.GetLocalPlayer();

            // Debug
            //DisplayChatAreaText("Reference to local player stored.");
        }
        try
        {
            if (!CheckWaterInRange())
            {
                if (boolAimingWater)
                {
                    boolAimingWater = false;
                    DisplayToolTipText("No, not a good place to put this...");
                }
                return;
            }
            else
            {
                if (!boolAimingWater)
                {
                    boolAimingWater = true;
                    DisplayToolTipText("Could work...");
                }
            }
        }
        catch (Exception)
        {
            DisplayChatAreaText("Opps, something is wrong with floater");
        }
        // Check if the player is already fishing
        if (boolAimingWater)
        {
            if (Input.GetKey(KeyCode.Keypad1) || Input.GetKey(KeyCode.Mouse0) || Input.GetMouseButton(0))
            {
                //DisplayChatAreaText("Place block here");
                boolPlaced = true;
                // place the "boat" at that position -> must be always the item name + B
                BlockValue offBlock = Block.GetBlockValue(_data.item.GetItemName() + "B");
                Block      block    = Block.list[offBlock.type];
                // spawns it on top of (if anything is there, it will be destroyed anyway
                GameManager.Instance.World.SetBlockRPC(vPlace, offBlock);
                _data.holdingEntity.inventory.DecHoldingItem(1);
                //_data.holdingEntity.inventory.SetItem(_data.holdingEntity.inventory.holdingItemIdx, new ItemStack(_itemValue, 1));
                //_data.itemStack.count = 0; // see if it just disapears.
                dteNextAction = DateTime.Now.AddSeconds(1);
            }
        }
    }
Пример #14
0
    public override void ExecuteAction(ItemActionData _actionData, bool _bReleased)
    {
        ItemActionSpawnCustomVehicle.ItemActionDataSpawnCustomVehicle itemActionDataSpawnMinibike = (ItemActionSpawnCustomVehicle.ItemActionDataSpawnCustomVehicle)_actionData;
        if (!(_actionData.invData.holdingEntity is EntityPlayerLocal))
        {
            return;
        }
        if (!_bReleased)
        {
            return;
        }
        if (Time.time - _actionData.lastUseTime < this.Delay)
        {
            return;
        }
        if (Time.time - _actionData.lastUseTime < Constants.cBuildIntervall)
        {
            return;
        }
        if (!itemActionDataSpawnMinibike.ValidPosition)
        {
            return;
        }
        ItemInventoryData invData = _actionData.invData;

        if (this.entityId < 0)
        {
            foreach (int v in EntityClass.list.Keys)
            {
                if (EntityClass.list[v].entityClassName == this.entityToSpawn)
                {
                    this.entityId = v;
                    break;
                }
            }
            if (this.entityId == 0)
            {
                return;
            }
        }
        if (!Steam.Network.IsServer)
        {
            SingletonMonoBehaviour <ConnectionManager> .Instance.SendToServer(new NetPackageVehicleSpawn(this.entityId, itemActionDataSpawnMinibike.Position, new Vector3(0f, _actionData.invData.holdingEntity.rotation.y + 90f, 0f), invData.holdingEntity.inventory.holdingItemItemValue.Clone(), _actionData.invData.holdingEntity.entityId), true);
        }
        else
        {
            EntityVehicle entityVehicle = (EntityVehicle)EntityFactory.CreateEntity(this.entityId, itemActionDataSpawnMinibike.Position, new Vector3(0f, _actionData.invData.holdingEntity.rotation.y + 90f, 0f));
            entityVehicle.SetSpawnerSource(EnumSpawnerSource.StaticSpawner);
            Vehicle vehicle = entityVehicle.GetVehicle();
            string  tag     = "chassis";
            if (invData.holdingEntity.inventory.holdingItem != null)
            {
                tag = invData.holdingEntity.inventory.holdingItem.VehicleSlotType;
            }
            vehicle.SetPartInSlot(tag, invData.holdingEntity.inventory.holdingItemItemValue.Clone());
            vehicle.SaveVehiclePartsToInventory();
            entityVehicle.SetOwner(GamePrefs.GetString(EnumGamePrefs.PlayerId));
            GameManager.Instance.World.SpawnEntityInWorld(entityVehicle);
        }
        invData.holdingEntity.RightArmAnimationUse = true;
        GameManager.Instance.StartCoroutine(this.EB(invData, invData.holdingEntity.inventory.holdingItemIdx));
    }