Ejemplo n.º 1
0
        public bool HandleDragDrop(IInventory sourceInventory, int sourceSlotIndex, DragMode dragMode, IInventory targetInventory, int targetSlotIndex)
        {
            int slotValue           = sourceInventory.GetSlotValue(sourceSlotIndex);
            int slotValue2          = targetInventory.GetSlotValue(targetSlotIndex);
            int num                 = sourceInventory.GetSlotCount(sourceSlotIndex);
            int slotCount           = targetInventory.GetSlotCount(targetSlotIndex);
            int slotCapacity        = targetInventory.GetSlotCapacity(targetSlotIndex, slotValue);
            int slotProcessCapacity = targetInventory.GetSlotProcessCapacity(targetSlotIndex, slotValue);

            if (dragMode == DragMode.SingleItem)
            {
                num = MathUtils.Min(num, 1);
            }
            bool flag = false;

            if (slotProcessCapacity > 0)
            {
                int processCount = sourceInventory.RemoveSlotItems(sourceSlotIndex, MathUtils.Min(num, slotProcessCapacity));
                targetInventory.ProcessSlotItems(targetSlotIndex, slotValue, num, processCount, out int processedValue, out int processedCount);
                if (processedValue != 0 && processedCount != 0)
                {
                    int count = MathUtils.Min(sourceInventory.GetSlotCapacity(sourceSlotIndex, processedValue), processedCount);
                    sourceInventory.AddSlotItems(sourceSlotIndex, processedValue, count);
                }
                flag = true;
            }
            else if (!ProcessingOnly && (slotCount == 0 || slotValue == slotValue2) && slotCount < slotCapacity)
            {
                int num2 = MathUtils.Min(slotCapacity - slotCount, num);
                if (num2 > 0)
                {
                    int count2 = sourceInventory.RemoveSlotItems(sourceSlotIndex, num2);
                    targetInventory.AddSlotItems(targetSlotIndex, slotValue, count2);
                    flag = true;
                }
            }
            else if (!ProcessingOnly && targetInventory.GetSlotCapacity(targetSlotIndex, slotValue) >= num && sourceInventory.GetSlotCapacity(sourceSlotIndex, slotValue2) >= slotCount && sourceInventory.GetSlotCount(sourceSlotIndex) == num)
            {
                int count3 = targetInventory.RemoveSlotItems(targetSlotIndex, slotCount);
                int count4 = sourceInventory.RemoveSlotItems(sourceSlotIndex, num);
                targetInventory.AddSlotItems(targetSlotIndex, slotValue, count4);
                sourceInventory.AddSlotItems(sourceSlotIndex, slotValue2, count3);
                flag = true;
            }
            if (flag)
            {
                AudioManager.PlaySound("Audio/UI/ItemMoved", 1f, 0f, 0f);
            }
            return(flag);
        }
Ejemplo n.º 2
0
        public override bool OnEditInventoryItem(IInventory inventory, int slotIndex, ComponentPlayer componentPlayer)
        {
            int value1           = inventory.GetSlotValue(slotIndex);
            int count            = inventory.GetSlotCount(slotIndex);
            int id               = Terrain.ExtractData(value1);
            var commandBlockData = GetItemData(id);

            if (commandBlockData != null)
            {
                commandBlockData = (CommandData)commandBlockData.Copy();
            }
            else
            {
                commandBlockData = new CommandData();
            }
            DialogsManager.ShowDialog(componentPlayer.View.GameWidget, new TextBoxDialog("enter a one-line command", commandBlockData.Command, 300, delegate(string result)
            {
                commandBlockData.Command = result;
                var data  = StoreItemDataAtUniqueId(commandBlockData);
                var value = Terrain.ReplaceData(value1, data);
                inventory.RemoveSlotItems(slotIndex, count);
                inventory.AddSlotItems(slotIndex, value, 1);
            }));
            return(true);
        }
Ejemplo n.º 3
0
        public override void ProcessInventoryItem(IInventory inventory, int slotIndex, int value, int count, int processCount, out int processedValue, out int processedCount)
        {
            processedValue = value;
            processedCount = count;
            if (processCount == 1)
            {
                int data = Terrain.ExtractData(inventory.GetSlotValue(slotIndex));
                MusketBlock.LoadState  loadState  = MusketBlock.GetLoadState(data);
                BulletBlock.BulletType?bulletType = MusketBlock.GetBulletType(data);
                switch (loadState)
                {
                case MusketBlock.LoadState.Empty:
                    loadState  = MusketBlock.LoadState.Gunpowder;
                    bulletType = null;
                    break;

                case MusketBlock.LoadState.Gunpowder:
                    loadState  = MusketBlock.LoadState.Wad;
                    bulletType = null;
                    break;

                case MusketBlock.LoadState.Wad:
                {
                    loadState = MusketBlock.LoadState.Loaded;
                    int data2 = Terrain.ExtractData(value);
                    bulletType = BulletBlock.GetBulletType(data2);
                    break;
                }
                }
                processedValue = 0;
                processedCount = 0;
                inventory.RemoveSlotItems(slotIndex, 1);
                inventory.AddSlotItems(slotIndex, Terrain.MakeBlockValue(212, 0, MusketBlock.SetBulletType(MusketBlock.SetLoadState(data, loadState), bulletType)), 1);
            }
        }
Ejemplo n.º 4
0
        public void SetDraw(int draw)
        {
            int data  = Terrain.ExtractData(m_inventory.GetSlotValue(m_slotIndex));
            int value = Terrain.MakeBlockValue(200, 0, CrossbowBlock.SetDraw(data, draw));

            m_inventory.RemoveSlotItems(m_slotIndex, 1);
            m_inventory.AddSlotItems(m_slotIndex, value, 1);
        }
 public static int AcquireItems(IInventory inventory, int value, int count)
 {
     while (count > 0)
     {
         int num = FindAcquireSlotForItem(inventory, value);
         if (num < 0)
         {
             break;
         }
         inventory.AddSlotItems(num, value, 1);
         count--;
     }
     return(count);
 }
Ejemplo n.º 6
0
        public static void moveInventory(IInventory a, IInventory b, ComponentPlayer player, GameMode mode)
        {
            bool remo = false;

            for (int i = 0; i < a.SlotsCount; i++)
            {         //遍历目标物品
                if (a.GetSlotCount(i) > 0)
                {     //该格有物品
                    for (int k = 0; k < b.SlotsCount; k++)
                    { //遍历背包
                        if ((b.GetSlotCount(k) == 0 || b.GetSlotValue(k) == a.GetSlotValue(i)))
                        {
                            //背包该格为空或者物品相同
                            //能够转移的数量
                            int needmovecnt = b.GetSlotCapacity(i, a.GetSlotValue(i)) - b.GetSlotCount(k);
                            //总共的转移数量
                            int allmovecnt = a.GetSlotCount(i);
                            if (needmovecnt >= allmovecnt)
                            {
                                needmovecnt = allmovecnt;
                            }
                            if (needmovecnt == 0)
                            {
                                i -= 1; continue;
                            }
                            else
                            {
                                if (mode != GameMode.Creative)
                                {
                                    b.AddSlotItems(k, a.GetSlotValue(i), needmovecnt);
                                }
                                a.RemoveSlotItems(i, needmovecnt);
                            }
                        }
                    }
                }
            }
            if (remo)
            {
                player.ComponentGui.DisplaySmallMessage("一键转移成功", Color.Red, false, false);
            }
            else
            {
                player.ComponentGui.DisplaySmallMessage("没有需要转移的物品呢", Color.Red, false, false);
            }
        }
Ejemplo n.º 7
0
 public override void ProcessInventoryItem(IInventory inventory, int slotIndex, int value, int count, int processCount, out int processedValue, out int processedCount)
 {
     if (processCount == 1)
     {
         ArrowBlock.ArrowType arrowType = ArrowBlock.GetArrowType(Terrain.ExtractData(value));
         int data = Terrain.ExtractData(inventory.GetSlotValue(slotIndex));
         processedValue = 0;
         processedCount = 0;
         inventory.RemoveSlotItems(slotIndex, 1);
         inventory.AddSlotItems(slotIndex, Terrain.MakeBlockValue(191, 0, BowBlock.SetArrowType(data, arrowType)), 1);
     }
     else
     {
         processedValue = value;
         processedCount = count;
     }
 }
Ejemplo n.º 8
0
        public override bool OnEditInventoryItem(IInventory inventory, int slotIndex, ComponentPlayer componentPlayer)
        {
            int value = inventory.GetSlotValue(slotIndex);
            int count = inventory.GetSlotCount(slotIndex);
            int data  = Terrain.ExtractData(value);

            DialogsManager.ShowDialog(componentPlayer.GuiWidget, new EditPistonDialog(data, delegate(int newData)
            {
                int num = Terrain.ReplaceData(value, newData);
                if (num != value)
                {
                    inventory.RemoveSlotItems(slotIndex, count);
                    inventory.AddSlotItems(slotIndex, num, 1);
                }
            }));
            return(true);
        }
Ejemplo n.º 9
0
        public bool HandleMoveItem(IInventory sourceInventory, int sourceSlotIndex, IInventory targetInventory, int targetSlotIndex, int count)
        {
            int slotValue  = sourceInventory.GetSlotValue(sourceSlotIndex);
            int slotValue2 = targetInventory.GetSlotValue(targetSlotIndex);
            int slotCount  = sourceInventory.GetSlotCount(sourceSlotIndex);
            int slotCount2 = targetInventory.GetSlotCount(targetSlotIndex);

            if (slotCount2 == 0 || slotValue == slotValue2)
            {
                int num = MathUtils.Min(targetInventory.GetSlotCapacity(targetSlotIndex, slotValue) - slotCount2, slotCount, count);
                if (num > 0)
                {
                    int count2 = sourceInventory.RemoveSlotItems(sourceSlotIndex, num);
                    targetInventory.AddSlotItems(targetSlotIndex, slotValue, count2);
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 10
0
        public override bool OnEditInventoryItem(IInventory inventory, int slotIndex, ComponentPlayer componentPlayer)
        {
            int value        = inventory.GetSlotValue(slotIndex);
            int count        = inventory.GetSlotCount(slotIndex);
            int data         = Terrain.ExtractData(value);
            int voltageLevel = BatteryBlock.GetVoltageLevel(data);

            DialogsManager.ShowDialog(componentPlayer.GuiWidget, new EditBatteryDialog(voltageLevel, delegate(int newVoltageLevel)
            {
                int data2 = BatteryBlock.SetVoltageLevel(data, newVoltageLevel);
                int num   = Terrain.ReplaceData(value, data2);
                if (num != value)
                {
                    inventory.RemoveSlotItems(slotIndex, count);
                    inventory.AddSlotItems(slotIndex, num, 1);
                }
            }));
            return(true);
        }
Ejemplo n.º 11
0
 public int saveInventory(IInventory inventory, int value, int count, int max)       //返回剩余的数量
 {
     if (inventory.GetSlotCount(0) == 0 || inventory.GetSlotValue(0) == value)
     {
         //计算拿取物品数量
         int nownum = inventory.GetSlotCount(0);
         int neednum;                //拿取数量
         int cannum = max - nownum;  //可以容纳数量
         if (count <= cannum)
         {
             neednum = count;
         }
         else
         {
             neednum = cannum;
         }
         inventory.AddSlotItems(0, value, neednum);
         return(count - neednum);
     }
     return(count);
 }
Ejemplo n.º 12
0
        public override void ProcessInventoryItem(IInventory inventory, int slotIndex, int value, int count, int processCount, out int processedValue, out int processedCount)
        {
            processedValue = value;
            processedCount = count;
            if (processCount == 1)
            {
                var loadState = Musket2Block.GetLoadState(Terrain.ExtractData(inventory.GetSlotValue(slotIndex)));
                switch (loadState)
                {
                case Musket2Block.LoadState.Empty:
                    loadState = Musket2Block.LoadState.Gunpowder;
                    break;

                case Musket2Block.LoadState.Gunpowder:
                    loadState = Musket2Block.LoadState.Wad;
                    break;
                }
                processedValue = 0;
                processedCount = 0;
                inventory.RemoveSlotItems(slotIndex, 1);
                inventory.AddSlotItems(slotIndex, Terrain.MakeBlockValue(Musket2Block.Index, 0, Musket2Block.SetBulletType(Musket2Block.SetLoadState(Terrain.ExtractData(inventory.GetSlotValue(slotIndex)), loadState), null)), 1);
            }
        }
Ejemplo n.º 13
0
        public override bool OnEditInventoryItem(IInventory inventory, int slotIndex, ComponentPlayer componentPlayer)
        {
            int            value          = inventory.GetSlotValue(slotIndex);
            int            count          = inventory.GetSlotCount(slotIndex);
            int            id             = Terrain.ExtractData(value);
            MemoryBankData memoryBankData = GetItemData(id);

            if (memoryBankData != null)
            {
                memoryBankData = (MemoryBankData)memoryBankData.Copy();
            }
            else
            {
                memoryBankData = new MemoryBankData();
            }
            DialogsManager.ShowDialog(componentPlayer.GuiWidget, new EditMemeryDialogB(memoryBankData, delegate() {
                int data   = StoreItemDataAtUniqueId(memoryBankData);
                int value2 = Terrain.ReplaceData(value, data);
                inventory.RemoveSlotItems(slotIndex, count);
                inventory.AddSlotItems(slotIndex, value2, 1);
            }));
            return(true);
        }
Ejemplo n.º 14
0
 public bool TryModifyItem(ScannedItemData itemData, int newValue)
 {
     if (itemData.Container is IInventory)
     {
         IInventory obj = (IInventory)itemData.Container;
         obj.RemoveSlotItems(itemData.IndexInContainer, itemData.Count);
         int slotCapacity = obj.GetSlotCapacity(itemData.IndexInContainer, newValue);
         obj.AddSlotItems(itemData.IndexInContainer, newValue, MathUtils.Min(itemData.Count, slotCapacity));
         return(true);
     }
     if (itemData.Container is WorldItem)
     {
         ((WorldItem)itemData.Container).Value = newValue;
         return(true);
     }
     if (itemData.Container is IMovingBlockSet)
     {
         IMovingBlockSet obj2        = (IMovingBlockSet)itemData.Container;
         MovingBlock     movingBlock = obj2.Blocks.ElementAt(itemData.IndexInContainer);
         obj2.SetBlock(movingBlock.Offset, newValue);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 15
0
        public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state)
        {
            IInventory inventory = componentMiner.Inventory;

            if (inventory != null)
            {
                int activeSlotIndex = inventory.ActiveSlotIndex;
                if (activeSlotIndex >= 0)
                {
                    int slotValue = inventory.GetSlotValue(activeSlotIndex);
                    int slotCount = inventory.GetSlotCount(activeSlotIndex);
                    int num       = Terrain.ExtractContents(slotValue);
                    int data      = Terrain.ExtractData(slotValue);
                    if (num == 191 && slotCount > 0)
                    {
                        if (!m_aimStartTimes.TryGetValue(componentMiner, out double value))
                        {
                            value = m_subsystemTime.GameTime;
                            m_aimStartTimes[componentMiner] = value;
                        }
                        float   num2 = (float)(m_subsystemTime.GameTime - value);
                        float   num3 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
                        Vector3 v    = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.02f : 0.04f) + 0.25f * MathUtils.Saturate((num2 - 2.1f) / 5f)) * new Vector3
                        {
                            X = SimplexNoise.OctavedNoise(num3, 2f, 3, 2f, 0.5f),
                            Y = SimplexNoise.OctavedNoise(num3 + 100f, 2f, 3, 2f, 0.5f),
                            Z = SimplexNoise.OctavedNoise(num3 + 200f, 2f, 3, 2f, 0.5f)
                        };
                        aim.Direction = Vector3.Normalize(aim.Direction + v);
                        switch (state)
                        {
                        case AimState.InProgress:
                        {
                            if (num2 >= 9f)
                            {
                                componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound();
                                return(true);
                            }
                            ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>();
                            if (componentFirstPersonModel != null)
                            {
                                componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction);
                                componentFirstPersonModel.ItemOffsetOrder   = new Vector3(-0.1f, 0.15f, 0f);
                                componentFirstPersonModel.ItemRotationOrder = new Vector3(0f, -0.7f, 0f);
                            }
                            componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder       = 1.2f;
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(0f, 0f, 0f);
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(0f, -0.2f, 0f);
                            if (m_subsystemTime.PeriodicGameTimeEvent(0.10000000149011612, 0.0))
                            {
                                int draw2 = MathUtils.Min(BowBlock.GetDraw(data) + 1, 15);
                                inventory.RemoveSlotItems(activeSlotIndex, 1);
                                inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, draw2)), 1);
                            }
                            break;
                        }

                        case AimState.Cancelled:
                            inventory.RemoveSlotItems(activeSlotIndex, 1);
                            inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0)), 1);
                            m_aimStartTimes.Remove(componentMiner);
                            break;

                        case AimState.Completed:
                        {
                            int draw = BowBlock.GetDraw(data);
                            ArrowBlock.ArrowType?arrowType = BowBlock.GetArrowType(data);
                            if (arrowType.HasValue)
                            {
                                Vector3 vector  = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
                                Vector3 vector2 = Vector3.Normalize(vector + aim.Direction * 10f - vector);
                                float   num4    = MathUtils.Lerp(0f, 28f, MathUtils.Pow((float)draw / 15f, 0.75f));
                                if (componentMiner.ComponentPlayer != null)
                                {
                                    num4 *= 0.5f * (componentMiner.ComponentPlayer.ComponentLevel.StrengthFactor - 1f) + 1f;
                                }
                                Vector3 vector3 = Vector3.Zero;
                                if (arrowType == ArrowBlock.ArrowType.WoodenArrow)
                                {
                                    vector3 = new Vector3(0.025f, 0.025f, 0.025f);
                                }
                                if (arrowType == ArrowBlock.ArrowType.StoneArrow)
                                {
                                    vector3 = new Vector3(0.01f, 0.01f, 0.01f);
                                }
                                int     value2  = Terrain.MakeBlockValue(192, 0, ArrowBlock.SetArrowType(0, arrowType.Value));
                                Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector2, Vector3.UnitY));
                                Vector3 v2      = Vector3.Normalize(Vector3.Cross(vector2, vector4));
                                Vector3 v3      = m_random.Float(0f - vector3.X, vector3.X) * vector4 + m_random.Float(0f - vector3.Y, vector3.Y) * v2 + m_random.Float(0f - vector3.Z, vector3.Z) * vector2;
                                if (m_subsystemProjectiles.FireProjectile(value2, vector, (vector2 + v3) * num4, Vector3.Zero, componentMiner.ComponentCreature) != null)
                                {
                                    data = BowBlock.SetArrowType(data, null);
                                    m_subsystemAudio.PlaySound("Audio/Bow", 1f, m_random.Float(-0.1f, 0.1f), vector, 3f, autoDelay: true);
                                }
                            }
                            else
                            {
                                componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load an arrow first", Color.White, blinking: true, playNotificationSound: false);
                            }
                            inventory.RemoveSlotItems(activeSlotIndex, 1);
                            int value3 = Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0));
                            inventory.AddSlotItems(activeSlotIndex, value3, 1);
                            int damageCount = 0;
                            if (draw >= 15)
                            {
                                damageCount = 2;
                            }
                            else if (draw >= 4)
                            {
                                damageCount = 1;
                            }
                            componentMiner.DamageActiveTool(damageCount);
                            m_aimStartTimes.Remove(componentMiner);
                            break;
                        }
                        }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 16
0
        public static void moveInventoryByCraft(IInventory srcInventory, IInventory toInventory, Dictionary <int, int> items, ComponentGui gui)
        {
            //items格式 id 数量
            Dictionary <int, int> fromList = new Dictionary <int, int>();
            Dictionary <int, int> toList   = new Dictionary <int, int>();

            for (int i = 0; i < srcInventory.SlotsCount; i++)
            {
                if (srcInventory.GetSlotCount(i) != 0)
                {
                    if (fromList.ContainsKey(srcInventory.GetSlotValue(i)))
                    {
                        fromList[srcInventory.GetSlotValue(i)] = srcInventory.GetSlotCount(i) + fromList[srcInventory.GetSlotValue(i)];
                    }
                    else
                    {
                        fromList.Add(srcInventory.GetSlotValue(i), srcInventory.GetSlotCount(i));
                    }
                }
            }
            for (int i = 0; i < toInventory.SlotsCount; i++)
            {
                if (srcInventory.GetSlotCount(i) != 0)
                {
                    if (toList.ContainsKey(toInventory.GetSlotValue(i)))
                    {
                        toList[srcInventory.GetSlotValue(i)] = toInventory.GetSlotCount(i) + toList[toInventory.GetSlotValue(i)];
                    }
                    else
                    {
                        toList.Add(toInventory.GetSlotValue(i), toInventory.GetSlotCount(i));
                    }
                }
            }
            int useSlotCount = 0; int ja = 0; int allcnt;

            //判断能否全部转移
            foreach (int id in fromList.Keys)
            {//id,cnt
                if (toList.ContainsKey(id))
                {
                    allcnt        = toList[id] + fromList[id];
                    useSlotCount += (int)Math.Ceiling((double)allcnt / (double)toInventory.GetSlotCapacity(ja, id));
                }
                else
                {
                    allcnt        = fromList[id];
                    useSlotCount += (int)Math.Ceiling((double)allcnt / (double)toInventory.GetSlotCapacity(ja, id));
                }
                ++ja;
            }
            if (useSlotCount > toInventory.SlotsCount)
            { //不能全部转移
                gui.DisplaySmallMessage("背包空间不足,不能转移物品", Color.Red, false, false);
            }
            else
            { //能全部转移
                //先移除全部
                for (int i = 0; i < srcInventory.SlotsCount; i++)
                {
                    if (srcInventory.GetSlotCount(i) == 0)
                    {
                        continue;
                    }
                    srcInventory.RemoveSlotItems(i, srcInventory.GetSlotCount(i));
                }
                for (int i = 0; i < toInventory.SlotsCount; i++)
                {
                    if (toInventory.GetSlotCount(i) == 0)
                    {
                        continue;
                    }
                    toInventory.RemoveSlotItems(i, toInventory.GetSlotCount(i));
                }
                int uu = 0;
                for (int i = 0; i < toInventory.SlotsCount; i++)
                {
                    for (int j = 0; j < (int)Math.Ceiling((double)toList[toList.Keys.ToArray()[i]] / (double)toInventory.GetSlotCapacity(ja, toList.Keys.ToArray()[i])); j++)//计算转移次数
                    {
                        int cap = toInventory.GetSlotCapacity(uu, toList.Keys.ToArray()[i]);
                        if (toList.Values.ToArray()[i] - cap < 0)
                        {
                            cap = toList.Values.ToArray()[i];
                        }
                        else
                        {
                            toList[toList.Keys.ToArray()[i]] = toList[toList.Keys.ToArray()[i]] - cap;
                        }
                        toInventory.AddSlotItems(uu, toList.Keys.ToArray()[i], cap);
                    }
                    ++uu;
                }
                gui.DisplaySmallMessage("转移成功!", Color.Red, false, false);
            }
        }
Ejemplo n.º 17
0
        public override bool OnAim(Vector3 start, Vector3 direction, ComponentMiner componentMiner, AimState state)
        {
            IInventory inventory = componentMiner.Inventory;

            if (inventory != null)
            {
                int activeSlotIndex = inventory.ActiveSlotIndex;
                if (activeSlotIndex >= 0)
                {
                    int slotValue = inventory.GetSlotValue(activeSlotIndex);
                    int slotCount = inventory.GetSlotCount(activeSlotIndex);
                    int num       = Terrain.ExtractContents(slotValue);
                    int data      = Terrain.ExtractData(slotValue);
                    int num2      = slotValue;
                    int num3      = 0;
                    if (num == Musket2Block.Index && slotCount > 0)
                    {
                        if (!m_aimStartTimes.TryGetValue(componentMiner, out double value))
                        {
                            value = m_subsystemTime.GameTime;
                            m_aimStartTimes[componentMiner] = value;
                        }
                        float   num4 = (float)(m_subsystemTime.GameTime - value);
                        float   num5 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
                        Vector3 v    = (float)((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.00999999977648258 : 0.0299999993294477) + 0.200000002980232 * MathUtils.Saturate((num4 - 6.5f) / 40f)) * new Vector3
                        {
                            X = SimplexNoise.OctavedNoise(num5, 2f, 3, 2f, 0.5f),
                            Y = SimplexNoise.OctavedNoise(num5 + 100f, 2f, 3, 2f, 0.5f),
                            Z = SimplexNoise.OctavedNoise(num5 + 200f, 2f, 3, 2f, 0.5f)
                        };
                        direction = Vector3.Normalize(direction + v);
                        switch (state)
                        {
                        case AimState.InProgress:
                        {
                            if (num4 >= 30f)
                            {
                                componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound();
                                return(true);
                            }
                            if (num4 > 0.2f && !Musket2Block.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(num, 0, Musket2Block.SetHammerState(Terrain.ExtractData(num2), true));
                                m_subsystemAudio.PlaySound("Audio/HammerCock", 1f, m_random.UniformFloat(-0.1f, 0.1f), 0f, 0f);
                            }
                            ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>();
                            if (componentFirstPersonModel != null)
                            {
                                ComponentPlayer componentPlayer2 = componentMiner.ComponentPlayer;
                                if (componentPlayer2 != null)
                                {
                                    componentPlayer2.ComponentGui.ShowAimingSights(start, direction);
                                }
                                componentFirstPersonModel.ItemOffsetOrder   = new Vector3(-0.21f, 0.15f, 0.08f);
                                componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f);
                            }
                            componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder       = 1.4f;
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(-0.08f, -0.08f, 0.07f);
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.7f, 0f, 0f);
                            break;
                        }

                        case AimState.Cancelled:
                            if (Musket2Block.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(num, 0, Musket2Block.SetHammerState(Terrain.ExtractData(num2), false));
                                m_subsystemAudio.PlaySound("Audio/HammerUncock", 1f, m_random.UniformFloat(-0.1f, 0.1f), 0f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;

                        case AimState.Completed:
                        {
                            bool    flag   = false;
                            int     value2 = 0;
                            int     num6   = 0;
                            float   s      = 0f;
                            Vector3 vector = Vector3.Zero;
                            Musket2Block.LoadState loadState = Musket2Block.GetLoadState(data);
                            if (Musket2Block.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                switch (loadState)
                                {
                                case Musket2Block.LoadState.Gunpowder:
                                    flag   = true;
                                    value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.IronBullet));
                                    s      = 320f;
                                    num6   = 1;
                                    vector = new Vector3(0.01f, 0.01f, 0.05f);
                                    goto default;

                                default:
                                    if (loadState == Musket2Block.LoadState.Wad)
                                    {
                                        flag   = true;
                                        value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.IronBullet));
                                        s      = 320f;
                                        num6   = 1;
                                        vector = new Vector3(0.01f, 0.01f, 0.05f);
                                    }
                                    break;

                                case Musket2Block.LoadState.Empty:
                                {
                                    ComponentPlayer componentPlayer = componentMiner.ComponentPlayer;
                                    if (componentPlayer != null)
                                    {
                                        componentPlayer.ComponentGui.DisplaySmallMessage("Load bullet first", true, false);
                                    }
                                    break;
                                }
                                }
                            }
                            if (flag)
                            {
                                if (componentMiner.ComponentCreature.ComponentBody.ImmersionFactor > 0.4f)
                                {
                                    m_subsystemAudio.PlaySound("Audio/MusketMisfire", 1f, m_random.UniformFloat(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, true);
                                }
                                else
                                {
                                    Vector3 eyePosition = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition;
                                    Matrix  matrix      = componentMiner.ComponentCreature.ComponentBody.Matrix;
                                    Vector3 v2          = eyePosition + matrix.Right * 0.3f;
                                    matrix = componentMiner.ComponentCreature.ComponentBody.Matrix;
                                    Vector3 vector2 = v2 - matrix.Up * 0.2f;
                                    var     vector3 = Vector3.Normalize(vector2 + direction * 10f - vector2);
                                    var     vector4 = Vector3.Normalize(Vector3.Cross(vector3, Vector3.UnitY));
                                    var     v3      = Vector3.Normalize(Vector3.Cross(vector3, vector4));
                                    for (int i = 0; i < num6; i++)
                                    {
                                        Vector3    v4         = m_random.UniformFloat(0f - vector.X, vector.X) * vector4 + m_random.UniformFloat(0f - vector.Y, vector.Y) * v3 + m_random.UniformFloat(0f - vector.Z, vector.Z) * vector3;
                                        Projectile projectile = m_subsystemProjectiles.FireProjectile(value2, vector2, s * (vector3 + v4), Vector3.Zero, componentMiner.ComponentCreature);
                                        if (projectile != null)
                                        {
                                            projectile.ProjectileStoppedAction = ProjectileStoppedAction.Disappear;
                                        }
                                    }
                                    m_subsystemAudio.PlaySound("Audio/MusketFire", 1f, m_random.UniformFloat(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 10f, true);
                                    m_subsystemParticles.AddParticleSystem(new GunSmokeParticleSystem(SubsystemTerrain, vector2 + 0.3f * vector3, vector3));
                                    m_subsystemNoise.MakeNoise(vector2, 1f, 40f);
                                    componentMiner.ComponentCreature.ComponentBody.ApplyImpulse(-1f * vector3);
                                }
                                if (loadState == Musket2Block.LoadState.Gunpowder)
                                {
                                    num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, Musket2Block.SetLoadState(Terrain.ExtractData(num2), Musket2Block.LoadState.Empty));
                                }
                                if (loadState == Musket2Block.LoadState.Wad)
                                {
                                    num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, Musket2Block.SetLoadState(Terrain.ExtractData(num2), Musket2Block.LoadState.Gunpowder));
                                }
                                num3 = 1;
                            }
                            if (Musket2Block.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, Musket2Block.SetHammerState(Terrain.ExtractData(num2), false));
                                m_subsystemAudio.PlaySound("Audio/HammerRelease", 1f, m_random.UniformFloat(-0.1f, 0.1f), 0f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;
                        }
                        }
                    }
                    if (num2 != slotValue)
                    {
                        inventory.RemoveSlotItems(activeSlotIndex, 1);
                        inventory.AddSlotItems(activeSlotIndex, num2, 1);
                    }
                    if (num3 > 0)
                    {
                        componentMiner.DamageActiveTool(num3);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 18
0
        public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state)
        {
            IInventory inventory = componentMiner.Inventory;

            if (inventory != null)
            {
                int activeSlotIndex = inventory.ActiveSlotIndex;
                if (activeSlotIndex >= 0)
                {
                    int slotValue = inventory.GetSlotValue(activeSlotIndex);
                    int slotCount = inventory.GetSlotCount(activeSlotIndex);
                    int num       = Terrain.ExtractContents(slotValue);
                    int data      = Terrain.ExtractData(slotValue);
                    int num2      = slotValue;
                    int num3      = 0;
                    if (num == 212 && slotCount > 0)
                    {
                        if (!m_aimStartTimes.TryGetValue(componentMiner, out double value))
                        {
                            value = m_subsystemTime.GameTime;
                            m_aimStartTimes[componentMiner] = value;
                        }
                        float   num4 = (float)(m_subsystemTime.GameTime - value);
                        float   num5 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
                        Vector3 v    = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.01f : 0.03f) + 0.2f * MathUtils.Saturate((num4 - 2.5f) / 6f)) * new Vector3
                        {
                            X = SimplexNoise.OctavedNoise(num5, 2f, 3, 2f, 0.5f),
                            Y = SimplexNoise.OctavedNoise(num5 + 100f, 2f, 3, 2f, 0.5f),
                            Z = SimplexNoise.OctavedNoise(num5 + 200f, 2f, 3, 2f, 0.5f)
                        };
                        aim.Direction = Vector3.Normalize(aim.Direction + v);
                        switch (state)
                        {
                        case AimState.InProgress:
                        {
                            if (num4 >= 10f)
                            {
                                componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound();
                                return(true);
                            }
                            if (num4 > 0.5f && !MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(num, 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: true));
                                m_subsystemAudio.PlaySound("Audio/HammerCock", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
                            }
                            ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>();
                            if (componentFirstPersonModel != null)
                            {
                                componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction);
                                componentFirstPersonModel.ItemOffsetOrder   = new Vector3(-0.21f, 0.15f, 0.08f);
                                componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f);
                            }
                            componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder       = 1.4f;
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(-0.08f, -0.08f, 0.07f);
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.7f, 0f, 0f);
                            break;
                        }

                        case AimState.Cancelled:
                            if (MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(num, 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: false));
                                m_subsystemAudio.PlaySound("Audio/HammerUncock", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;

                        case AimState.Completed:
                        {
                            bool    flag   = false;
                            int     value2 = 0;
                            int     num6   = 0;
                            float   s      = 0f;
                            Vector3 vector = Vector3.Zero;
                            MusketBlock.LoadState  loadState  = MusketBlock.GetLoadState(data);
                            BulletBlock.BulletType?bulletType = MusketBlock.GetBulletType(data);
                            if (MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                switch (loadState)
                                {
                                case MusketBlock.LoadState.Empty:
                                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load gunpowder first", Color.White, blinking: true, playNotificationSound: false);
                                    break;

                                case MusketBlock.LoadState.Gunpowder:
                                case MusketBlock.LoadState.Wad:
                                    flag = true;
                                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("No bullet, blind shot fired", Color.White, blinking: true, playNotificationSound: false);
                                    break;

                                case MusketBlock.LoadState.Loaded:
                                    flag = true;
                                    if (bulletType == BulletBlock.BulletType.Buckshot)
                                    {
                                        value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.BuckshotBall));
                                        num6   = 8;
                                        vector = new Vector3(0.04f, 0.04f, 0.25f);
                                        s      = 80f;
                                    }
                                    else if (bulletType == BulletBlock.BulletType.BuckshotBall)
                                    {
                                        value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.BuckshotBall));
                                        num6   = 1;
                                        vector = new Vector3(0.06f, 0.06f, 0f);
                                        s      = 60f;
                                    }
                                    else if (bulletType.HasValue)
                                    {
                                        value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, bulletType.Value));
                                        num6   = 1;
                                        s      = 120f;
                                    }
                                    break;
                                }
                            }
                            if (flag)
                            {
                                if (componentMiner.ComponentCreature.ComponentBody.ImmersionFactor > 0.4f)
                                {
                                    m_subsystemAudio.PlaySound("Audio/MusketMisfire", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, autoDelay: true);
                                }
                                else
                                {
                                    Vector3 vector2 = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
                                    Vector3 vector3 = Vector3.Normalize(vector2 + aim.Direction * 10f - vector2);
                                    Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector3, Vector3.UnitY));
                                    Vector3 v2      = Vector3.Normalize(Vector3.Cross(vector3, vector4));
                                    for (int i = 0; i < num6; i++)
                                    {
                                        Vector3    v3         = m_random.Float(0f - vector.X, vector.X) * vector4 + m_random.Float(0f - vector.Y, vector.Y) * v2 + m_random.Float(0f - vector.Z, vector.Z) * vector3;
                                        Projectile projectile = m_subsystemProjectiles.FireProjectile(value2, vector2, s * (vector3 + v3), Vector3.Zero, componentMiner.ComponentCreature);
                                        if (projectile != null)
                                        {
                                            projectile.ProjectileStoppedAction = ProjectileStoppedAction.Disappear;
                                        }
                                    }
                                    m_subsystemAudio.PlaySound("Audio/MusketFire", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 10f, autoDelay: true);
                                    m_subsystemParticles.AddParticleSystem(new GunSmokeParticleSystem(m_subsystemTerrain, vector2 + 0.3f * vector3, vector3));
                                    m_subsystemNoise.MakeNoise(vector2, 1f, 40f);
                                    componentMiner.ComponentCreature.ComponentBody.ApplyImpulse(-4f * vector3);
                                }
                                num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, MusketBlock.SetLoadState(Terrain.ExtractData(num2), MusketBlock.LoadState.Empty));
                                num3 = 1;
                            }
                            if (MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: false));
                                m_subsystemAudio.PlaySound("Audio/HammerRelease", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;
                        }
                        }
                    }
                    if (num2 != slotValue)
                    {
                        inventory.RemoveSlotItems(activeSlotIndex, 1);
                        inventory.AddSlotItems(activeSlotIndex, num2, 1);
                    }
                    if (num3 > 0)
                    {
                        componentMiner.DamageActiveTool(num3);
                    }
                }
            }
            return(false);
        }
        public override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
        {
            IInventory inventory        = componentMiner.Inventory;
            int        activeBlockValue = componentMiner.ActiveBlockValue;
            int        num = Terrain.ExtractContents(activeBlockValue);

            if (num == 90)
            {
                object obj = componentMiner.Raycast(ray, RaycastMode.Gathering);
                if (obj is TerrainRaycastResult)
                {
                    CellFace cellFace  = ((TerrainRaycastResult)obj).CellFace;
                    int      cellValue = base.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z);
                    int      num2      = Terrain.ExtractContents(cellValue);
                    int      data      = Terrain.ExtractData(cellValue);
                    Block    block     = BlocksManager.Blocks[num2];
                    if (block is WaterBlock && FluidBlock.GetLevel(data) == 0)
                    {
                        int value = Terrain.ReplaceContents(activeBlockValue, 91);
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value, 1);
                        }
                        base.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, noDrop: false, noParticleSystem: false);
                        return(true);
                    }
                    if (block is MagmaBlock && FluidBlock.GetLevel(data) == 0)
                    {
                        int value2 = Terrain.ReplaceContents(activeBlockValue, 93);
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value2, 1);
                        }
                        base.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, noDrop: false, noParticleSystem: false);
                        return(true);
                    }
                }
                else if (obj is BodyRaycastResult)
                {
                    ComponentUdder componentUdder = ((BodyRaycastResult)obj).ComponentBody.Entity.FindComponent <ComponentUdder>();
                    if (componentUdder != null && componentUdder.Milk(componentMiner))
                    {
                        int value3 = Terrain.ReplaceContents(activeBlockValue, 110);
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value3, 1);
                        }
                        m_subsystemAudio.PlaySound("Audio/Milked", 1f, 0f, ray.Position, 2f, autoDelay: true);
                    }
                    return(true);
                }
            }
            if (num == 91)
            {
                TerrainRaycastResult?terrainRaycastResult = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction);
                if (terrainRaycastResult.HasValue && componentMiner.Place(terrainRaycastResult.Value, Terrain.MakeBlockValue(18)))
                {
                    inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
                    if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                    {
                        int value4 = Terrain.ReplaceContents(activeBlockValue, 90);
                        inventory.AddSlotItems(inventory.ActiveSlotIndex, value4, 1);
                    }
                    return(true);
                }
            }
            if (num == 93)
            {
                TerrainRaycastResult?terrainRaycastResult2 = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction);
                if (terrainRaycastResult2.HasValue)
                {
                    if (componentMiner.Place(terrainRaycastResult2.Value, Terrain.MakeBlockValue(92)))
                    {
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            int value5 = Terrain.ReplaceContents(activeBlockValue, 90);
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value5, 1);
                        }
                    }
                    return(true);
                }
            }
            switch (num)
            {
            case 110:
            case 245:
                return(true);

            case 251:
            case 252:
                return(true);

            case 128:
            case 129:
            {
                TerrainRaycastResult?terrainRaycastResult3 = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Digging);
                if (terrainRaycastResult3.HasValue)
                {
                    CellFace cellFace2  = terrainRaycastResult3.Value.CellFace;
                    int      cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(cellFace2.X, cellFace2.Y, cellFace2.Z);
                    int      num3       = Terrain.ExtractContents(cellValue2);
                    Block    block2     = BlocksManager.Blocks[num3];
                    if (block2 is IPaintableBlock)
                    {
                        Vector3 normal   = CellFace.FaceToVector3(terrainRaycastResult3.Value.CellFace.Face);
                        Vector3 position = terrainRaycastResult3.Value.HitPoint();
                        int?    num4     = (num == 128) ? null : new int?(PaintBucketBlock.GetColor(Terrain.ExtractData(activeBlockValue)));
                        Color   color    = num4.HasValue ? SubsystemPalette.GetColor(base.SubsystemTerrain, num4) : new Color(128, 128, 128, 128);
                        int     value6   = ((IPaintableBlock)block2).Paint(base.SubsystemTerrain, cellValue2, num4);
                        base.SubsystemTerrain.ChangeCell(cellFace2.X, cellFace2.Y, cellFace2.Z, value6);
                        componentMiner.DamageActiveTool(1);
                        m_subsystemAudio.PlayRandomSound("Audio/Paint", 0.4f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentBody.Position, 2f, autoDelay: true);
                        m_subsystemParticles.AddParticleSystem(new PaintParticleSystem(base.SubsystemTerrain, position, normal, color));
                    }
                    return(true);
                }
                break;
            }
            }
            return(false);
        }
Ejemplo n.º 20
0
        public override bool OnUse(Vector3 start, Vector3 direction, ComponentMiner componentMiner)
        {
            int               activeBlockValue = componentMiner.ActiveBlockValue;
            var               result           = componentMiner.PickTerrainForDigging(start, direction);
            Entity            entity;
            Vector3           position;
            BodyRaycastResult?body;

            if (activeBlockValue == ItemBlock.IdTable["Wrench"])
            {
                body = componentMiner.PickBody(start, direction);
                Matrix matrix = componentMiner.ComponentCreature.ComponentBody.Matrix;
                position = matrix.Translation + 1f * matrix.Forward + Vector3.UnitY;
                if (body.HasValue && (!result.HasValue || body.Value.Distance < result.Value.Distance))
                {
                    entity = body.Value.ComponentBody.Entity;
                    if (entity.FindComponent <ComponentTrain>() != null || entity.FindComponent <ComponentBoatI>() != null)
                    {
                        for (var i = entity.FindComponents <IInventory>().GetEnumerator(); i.MoveNext();)
                        {
                            i.Current.DropAllItems(position);
                        }
                        Utils.SubsystemPickables.AddPickable(ItemBlock.IdTable[entity.ValuesDictionary.DatabaseObject.Name.Length == 8 ? "Minecart" : entity.ValuesDictionary.DatabaseObject.Name], 1, position, null, null);
                        Project.RemoveEntity(entity, true);
                        return(true);
                    }
                }
            }
            else if ((activeBlockValue == ItemBlock.IdTable["Train"] || activeBlockValue == ItemBlock.IdTable["Minecart"]) && result.HasValue && Terrain.ExtractContents(result.Value.Value) == RailBlock.Index)
            {
                position = new Vector3(result.Value.CellFace.Point) + new Vector3(0.5f);
                entity   = DatabaseManager.CreateEntity(Project, activeBlockValue == ItemBlock.IdTable["Minecart"] ? "Carriage" : "Train", true);

                var rotation = componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation.ToForwardVector();
                entity.FindComponent <ComponentTrain>(true).SetDirection(RailBlock.IsDirectionX(RailBlock.GetRailType(Terrain.ExtractData(result.Value.Value)))
                                        ? rotation.Z < 0 ? 0 : 2
                                        : rotation.X < 0 ? 1 : 3);
                entity.FindComponent <ComponentBody>(true).Position       = position;
                entity.FindComponent <ComponentSpawn>(true).SpawnDuration = 0f;
                Project.AddEntity(entity);
                var componentTrain = entity.FindComponent <ComponentTrain>(true);
                if (activeBlockValue == ItemBlock.IdTable["Minecart"])
                {
                    componentTrain.Update(0);
                    var train = componentTrain.FindNearestTrain();
                    if (train != null)
                    {
                        componentTrain.ParentBody = train;
                    }
                }
                componentMiner.RemoveActiveTool(1);
                Utils.SubsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, position, 3f, true);
                return(true);
            }

            /*else if (activeBlockValue == ItemBlock.IdTable["Minecart"])
             * {
             *      entity = DatabaseManager.CreateEntity(Project, "Carriage", true);
             *      body = componentMiner.PickBody(start, direction);
             *      if (body.HasValue && (!result.HasValue || body.Value.Distance < result.Value.Distance))
             *      {
             *              body = componentMiner.PickBody(start, direction);
             *              var componentTrain = entity.FindComponent<ComponentTrain>(true);
             *              var train = body.Value.ComponentBody.Entity.FindComponent<ComponentTrain>();
             *              if (train != null)
             *                      componentTrain.ParentBody = train;
             *      }
             *      else if (result.HasValue)
             *              position = result.Value.RaycastStart + Vector3.Normalize(result.Value.RaycastEnd - result.Value.RaycastStart) * result.Value.Distance; ;
             *      var rotation = componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation.ToForwardVector();
             *      entity.FindComponent<ComponentTrain>(true).SetDirection(RailBlock.IsDirectionX(RailBlock.GetRailType(Terrain.ExtractData(result.Value.Value)))
             *              ? rotation.Z < 0 ? 0 : 2
             *              : rotation.X < 0 ? 1 : 3);
             *      goto put;
             * }*/
            else if (activeBlockValue == ItemBlock.IdTable["基因查看器"])
            {
                body = componentMiner.PickBody(start, direction);
                if (body.HasValue && (!result.HasValue || body.Value.Distance < result.Value.Distance))
                {
                    var cv = body.Value.ComponentBody.Entity.FindComponent <ComponentVariant>();
                    if (cv != null)
                    {
                        DialogsManager.ShowDialog(componentMiner.ComponentPlayer?.View.GameWidget, new MessageDialog("Result", cv.Genome.ToString(), "OK", null, null));
                    }
                    return(true);
                }
            }
            else if (result.HasValue)
            {
                position = result.Value.RaycastStart + Vector3.Normalize(result.Value.RaycastEnd - result.Value.RaycastStart) * result.Value.Distance;
                if (activeBlockValue == ItemBlock.IdTable["SteamBoat"])
                {
                    entity = DatabaseManager.CreateEntity(Project, "SteamBoat", true);
                    entity.FindComponent <ComponentFrame>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.UniformFloat(0f, 6.283185f));
                    goto put;
                }

                /*else if (activeBlockValue == ItemBlock.IdTable["Minecart"])
                 * {
                 *      entity = DatabaseManager.CreateEntity(Project, "Carriage", true);
                 *      entity.FindComponent<ComponentFrame>(true).Position = position;
                 *      entity.FindComponent<ComponentSpawn>(true).SpawnDuration = 0f;
                 *      var componentTrain = entity.FindComponent<ComponentTrain>(true);
                 *      var componentMount = componentTrain.FindNearestTrain();
                 *      if (componentMount != null)
                 *              componentTrain.ParentBody = componentMount.m_componentBody;
                 *      goto put;
                 * }*/
                else if (activeBlockValue == ItemBlock.IdTable["Airship"])
                {
                    entity = DatabaseManager.CreateEntity(Project, "Airship", true);
                    entity.FindComponent <ComponentFrame>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.UniformFloat(0f, 6.283185f));
                    goto put;
                }
                else if (BlocksManager.Blocks[Terrain.ExtractContents(activeBlockValue)] is ItemBlock itemblock && itemblock.GetItem(ref activeBlockValue) is Mine mine)
                {
                    entity = DatabaseManager.CreateEntity(Project, "Mine", new ValuesDictionary
                    {
                        { "Mine", new ValuesDictionary {
                              { "Type", mine.MineType }
                          } }
                    }, true);
                    entity.FindComponent <ComponentFrame>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.UniformFloat(0f, 6.283185f));
                    var componentMine = entity.FindComponent <ComponentMine>(true);
                    componentMine.ExplosionPressure = mine.ExplosionPressure;
                    componentMine.Delay             = mine.Delay;
                    goto put;
                }
            }
            IInventory           inventory = componentMiner.Inventory;
            TerrainRaycastResult?result2;

            if (Terrain.ExtractContents(activeBlockValue) == 90)
            {
                result2 = componentMiner.PickTerrainForGathering(start, direction);
                if (result2.HasValue)
                {
                    CellFace cellFace  = result2.Value.CellFace;
                    int      cellValue = Terrain.ReplaceLight(Utils.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z), 0);
                    if (cellValue != (RottenMeatBlock.Index | 1 << 4 << 14))
                    {
                        return(false);
                    }
                    inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                    if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                    {
                        inventory.AddSlotItems(inventory.ActiveSlotIndex, RottenMeatBlock.Index | 2 << 4 << 14, 1);
                    }
                    Utils.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, false, false);
                    return(true);
                }
            }
            if (activeBlockValue == (RottenMeatBlock.Index | 2 << 4 << 14))
            {
                result2 = componentMiner.PickTerrainForInteraction(start, direction);
                if (result2.HasValue && componentMiner.Place(result2.Value, RottenMeatBlock.Index | 1 << 4 << 14))
                {
                    inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
                    if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                    {
                        inventory.AddSlotItems(inventory.ActiveSlotIndex, Terrain.ReplaceContents(activeBlockValue, 90), 1);
                    }
                    return(true);
                }
            }
            return(false);

put:
            entity.FindComponent <ComponentBody>(true).Position       = position;
            entity.FindComponent <ComponentSpawn>(true).SpawnDuration = 0f;
            Project.AddEntity(entity);
            componentMiner.RemoveActiveTool(1);
            Utils.SubsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, position, 3f, true);
            return(true);
        }
        public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state)
        {
            IInventory inventory = componentMiner.Inventory;

            if (inventory != null)
            {
                int activeSlotIndex = inventory.ActiveSlotIndex;
                if (activeSlotIndex >= 0)
                {
                    int slotValue = inventory.GetSlotValue(activeSlotIndex);
                    int slotCount = inventory.GetSlotCount(activeSlotIndex);
                    int num       = Terrain.ExtractContents(slotValue);
                    int data      = Terrain.ExtractData(slotValue);
                    if (num == 200 && slotCount > 0)
                    {
                        int draw = CrossbowBlock.GetDraw(data);
                        if (!m_aimStartTimes.TryGetValue(componentMiner, out double value))
                        {
                            value = m_subsystemTime.GameTime;
                            m_aimStartTimes[componentMiner] = value;
                        }
                        float   num2 = (float)(m_subsystemTime.GameTime - value);
                        float   num3 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
                        Vector3 v    = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.01f : 0.03f) + 0.15f * MathUtils.Saturate((num2 - 2.5f) / 6f)) * new Vector3
                        {
                            X = SimplexNoise.OctavedNoise(num3, 2f, 3, 2f, 0.5f),
                            Y = SimplexNoise.OctavedNoise(num3 + 100f, 2f, 3, 2f, 0.5f),
                            Z = SimplexNoise.OctavedNoise(num3 + 200f, 2f, 3, 2f, 0.5f)
                        };
                        aim.Direction = Vector3.Normalize(aim.Direction + v);
                        switch (state)
                        {
                        case AimState.InProgress:
                        {
                            if (num2 >= 10f)
                            {
                                componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound();
                                return(true);
                            }
                            ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>();
                            if (componentFirstPersonModel != null)
                            {
                                componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction);
                                componentFirstPersonModel.ItemOffsetOrder   = new Vector3(-0.22f, 0.15f, 0.1f);
                                componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f);
                            }
                            componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder       = 1.3f;
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(-0.08f, -0.1f, 0.07f);
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.55f, 0f, 0f);
                            break;
                        }

                        case AimState.Cancelled:
                            m_aimStartTimes.Remove(componentMiner);
                            break;

                        case AimState.Completed:
                        {
                            ArrowBlock.ArrowType?arrowType = CrossbowBlock.GetArrowType(data);
                            if (draw != 15)
                            {
                                componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Draw the crossbow first", Color.White, blinking: true, playNotificationSound: false);
                            }
                            else if (!arrowType.HasValue)
                            {
                                componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load a bolt first", Color.White, blinking: true, playNotificationSound: false);
                            }
                            else
                            {
                                Vector3 vector = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
                                Vector3 v2     = Vector3.Normalize(vector + aim.Direction * 10f - vector);
                                int     value2 = Terrain.MakeBlockValue(192, 0, ArrowBlock.SetArrowType(0, arrowType.Value));
                                float   s      = 38f;
                                if (m_subsystemProjectiles.FireProjectile(value2, vector, s * v2, Vector3.Zero, componentMiner.ComponentCreature) != null)
                                {
                                    data = CrossbowBlock.SetArrowType(data, null);
                                    m_subsystemAudio.PlaySound("Audio/Bow", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, 0.05f);
                                }
                            }
                            inventory.RemoveSlotItems(activeSlotIndex, 1);
                            int value3 = Terrain.MakeBlockValue(num, 0, CrossbowBlock.SetDraw(data, 0));
                            inventory.AddSlotItems(activeSlotIndex, value3, 1);
                            if (draw > 0)
                            {
                                componentMiner.DamageActiveTool(1);
                                m_subsystemAudio.PlaySound("Audio/CrossbowBoing", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;
                        }
                        }
                    }
                }
            }
            return(false);
        }