GetToolCooldown() public method

public GetToolCooldown ( PlayerTools tool ) : float
tool PlayerTools
return float
Esempio n. 1
0
        public void UsePickaxe(Player player, Vector3 playerPosition, Vector3 playerHeading)
        {
            player.QueueAnimationBreak = true;

            // Figure out what we're hitting.
            Vector3 hitPoint = Vector3.Zero;
            Vector3 buildPoint = Vector3.Zero;

            if (artifactActive[(byte)player.Team, 4] > 0 || player.Content[10] == 4)
            {
                if (!RayCollision(playerPosition, playerHeading, 2, 10, ref hitPoint, ref buildPoint, BlockType.Water))
                {
                    //ConsoleWrite(player.Handle + " lost a block sync.");
                    return;
                }
            }
            else
            {
                if (!RayCollision(playerPosition, playerHeading, 2, 10, ref hitPoint, ref buildPoint, BlockType.None))
                {
                    //ConsoleWrite(player.Handle + " lost a block sync.");
                    return;
                }
            }
            ushort x = (ushort)hitPoint.X;
            ushort y = (ushort)hitPoint.Y;
            ushort z = (ushort)hitPoint.Z;

            if (player.Alive == false || player.playerToolCooldown > DateTime.Now)
            {
                //ConsoleWrite("fixed " + player.Handle + " synchronization");
                SetBlockForPlayer(x, y, z, blockList[x, y, z], blockCreatorTeam[x, y, z], player);
                return;
            }
            else
            {
                player.playerToolCooldown = DateTime.Now + TimeSpan.FromSeconds((float)(player.GetToolCooldown(PlayerTools.Pickaxe)));
            }
            // Figure out what the result is.
            bool removeBlock = false;
            uint giveOre = 0;
            uint giveCash = 0;
            uint giveWeight = 0;
            int Damage = 2 + ResearchComplete[(byte)player.Team, 5];
            InfiniminerSound sound = InfiniminerSound.DigDirt;
            BlockType block = BlockAtPoint(hitPoint);
            switch (block)
            {
                case BlockType.Lava:
                    if (varGetB("minelava"))
                    {
                        removeBlock = true;
                        sound = InfiniminerSound.DigDirt;
                    }
                    break;
                case BlockType.Water:
                    if (varGetB("minelava"))
                    {
                        removeBlock = true;
                        sound = InfiniminerSound.DigDirt;
                    }
                    break;
                case BlockType.Dirt:
                case BlockType.Mud:
                case BlockType.Grass:
                case BlockType.Sand:
                case BlockType.DirtSign:
                    removeBlock = true;
                    sound = InfiniminerSound.DigDirt;
                    break;
                case BlockType.StealthBlockB:
                    removeBlock = true;
                    sound = InfiniminerSound.DigDirt;
                    break;
                case BlockType.StealthBlockR:
                    removeBlock = true;
                    sound = InfiniminerSound.DigDirt;
                    break;
                case BlockType.TrapB:
                    removeBlock = true;
                    sound = InfiniminerSound.DigDirt;
                    break;
                case BlockType.TrapR:
                    removeBlock = true;
                    sound = InfiniminerSound.DigDirt;
                    break;
                case BlockType.Ore:
                    removeBlock = true;
                    giveOre = 20;
                    sound = InfiniminerSound.DigMetal;
                    break;

                case BlockType.Gold:
                    Damage = 2;
                    giveWeight = 1;
                    giveCash = 10;
                    sound = InfiniminerSound.DigMetal;
                    break;

                case BlockType.Diamond:
                    //removeBlock = true;
                    //giveWeight = 1;
                    //giveCash = 1000;
                    sound = InfiniminerSound.DigMetal;
                    break;

                case BlockType.SolidRed:
                case BlockType.SolidBlue:
                case BlockType.SolidRed2:
                case BlockType.SolidBlue2:
                    sound = InfiniminerSound.DigMetal;
                    break;

                default:
                    break;
            }

            if (giveOre > 0)
            {
                if (player.Ore < player.OreMax - giveOre)
                {
                    player.Ore += giveOre;
                    SendOreUpdate(player);
                }
                else if(player.Ore < player.OreMax)//vaporize some ore to fit into players inventory
                {
                    player.Ore = player.OreMax;
                    SendOreUpdate(player);
                }
                else//ore goes onto ground
                {
                    SetItem(ItemType.Ore, hitPoint - (playerHeading * 0.3f), playerHeading, new Vector3(playerHeading.X * 1.5f, 0.0f, playerHeading.Z * 1.5f), PlayerTeam.None, 0);
                }
            }

            if (giveWeight > 0)
            {
                if (player.Weight < player.WeightMax)
                {
                    player.Weight = Math.Min(player.Weight + giveWeight, player.WeightMax);
                    player.Cash += giveCash;
                    SendWeightUpdate(player);
                    SendCashUpdate(player);
                }
                else
                {
                    removeBlock = false;
                    if (block == BlockType.Gold)
                    {
                        if (player.Weight == player.WeightMax)
                        {
                            //gold goes onto the ground
                            SetItem(ItemType.Gold, hitPoint, playerHeading, new Vector3(playerHeading.X * 1.5f, 0.0f, playerHeading.Z * 1.5f), PlayerTeam.None, 0);
                        }
                    }
                }
            }

            if (removeBlock)//block falls away with any hit
            {
                //SetBlock(x, y, z, BlockType.None, PlayerTeam.None);
                SetBlockDebris(x, y, z, BlockType.None, PlayerTeam.None);//blockset + adds debris for all players
                PlaySoundForEveryoneElse(sound, player.Position, player);
            }
            else if (Damage > 0 && BlockInformation.GetMaxHP(block) > 0)//this block is resistant to pickaxes
            {
                if (blockCreatorTeam[x, y, z] != player.Team)//block does not belong to us: destroy it
                {
                    if (blockListHP[x, y, z] < Damage)
                    {
                        if(block == BlockType.RadarRed)
                        {
                            foreach (Player p in playerList.Values)
                            {
                                if (p.Alive && p.Team == PlayerTeam.Blue)
                                {
                                    if (p.Content[1] == 1)
                                    {
                                        p.Content[1] = 0;//goes off radar again
                                        SendPlayerContentUpdate(p, 1);
                                    }
                                }
                            }
                        }
                        else if(block == BlockType.RadarBlue)
                        {
                            foreach (Player p in playerList.Values)
                            {
                                if (p.Alive && p.Team == PlayerTeam.Red)
                                {
                                    if (p.Content[1] == 1)
                                    {
                                        p.Content[1] = 0;//goes off radar again
                                        SendPlayerContentUpdate(p, 1);
                                    }
                                }
                            }
                        }
                        else if (block == BlockType.ArtCaseR || block == BlockType.ArtCaseB)
                        {
                            if (y < MAPSIZE - 1)
                                if (blockList[x, y + 1, z] == BlockType.ForceR || blockList[x, y + 1, z] == BlockType.ForceB)
                                {
                                    SetBlock(x, (ushort)(y + 1), z, BlockType.None, PlayerTeam.None);
                                }

                            if (blockListContent[x, y, z, 6] > 0)
                            {
                                uint arty = (uint)(blockListContent[x, y, z, 6]);
                                itemList[arty].Content[6] = 0;//unlock arty
                                SendItemContentSpecificUpdate(itemList[(uint)(blockListContent[x, y, z, 6])], 6);

                                if (blockList[x, y, z] == BlockType.ArtCaseR)
                                    ArtifactTeamBonus(PlayerTeam.Red, itemList[arty].Content[10], false);
                                else if (blockList[x, y, z] == BlockType.ArtCaseB)
                                    ArtifactTeamBonus(PlayerTeam.Blue, itemList[arty].Content[10], false);

                                if (blockList[x, y, z] == BlockType.ArtCaseB)
                                {
                                    teamArtifactsBlue--;
                                    SendScoreUpdate();
                                }
                                else if (blockList[x, y, z] == BlockType.ArtCaseR)
                                {
                                    teamArtifactsRed--;
                                    SendScoreUpdate();
                                }
                            }

                            NetBuffer msgBuffer = netServer.CreateBuffer();
                            msgBuffer = netServer.CreateBuffer();
                            msgBuffer.Write((byte)InfiniminerMessage.ChatMessage);

                            if(block == BlockType.ArtCaseB)
                                msgBuffer.Write((byte)ChatMessageType.SayBlueTeam);
                            else if(block == BlockType.ArtCaseR)
                                msgBuffer.Write((byte)ChatMessageType.SayRedTeam);

                            msgBuffer.Write(Defines.Sanitize("The enemy team has destroyed one of our artifact safehouses!"));

                            foreach (NetConnection netConn in playerList.Keys)
                                if (netConn.Status == NetConnectionStatus.Connected)
                                    if (playerList[netConn].Team == PlayerTeam.Red && block == BlockType.ArtCaseR)
                                    {
                                        netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableUnordered);
                                    }
                                    else if (playerList[netConn].Team == PlayerTeam.Blue && block == BlockType.ArtCaseB)
                                    {
                                        netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableUnordered);
                                    }

                        }
                        else if (block == BlockType.Diamond)
                        {
                            uint piece = SetItem(ItemType.Diamond, new Vector3(x + 0.5f, y + 0.5f, z + 0.5f), Vector3.Zero, Vector3.Zero, PlayerTeam.None, 0);
                        }

                        SetBlockDebris(x, y, z, BlockType.None, PlayerTeam.None);//blockset + adds debris for all players

                        blockListHP[x, y, z] = 0;
                        sound = InfiniminerSound.Explosion;
                    }
                    else
                    {
                        hitPoint -= playerHeading * 0.3f;

                        DebrisEffectAtPoint(hitPoint.X, hitPoint.Y, hitPoint.Z, block, 0);

                        blockListHP[x, y, z] -= Damage;
                        hitPoint -= (playerHeading*0.4f);

                        if (block == BlockType.SolidRed2 || block == BlockType.SolidBlue2)
                        {
                            if (blockListHP[x, y, z] < 21)
                            {
                                SetBlock(x, y, z, blockCreatorTeam[x, y, z] == PlayerTeam.Red ? BlockType.SolidRed : BlockType.SolidBlue, blockCreatorTeam[x, y, z]);
                            }
                        }
                        else if (block == BlockType.Gold)
                        {
                            PlaySoundForEveryoneElse(InfiniminerSound.RadarLow, new Vector3(x + 0.5f, y + 0.5f, z + 0.5f), player);
                            //InfiniminerSound.RadarHigh
                        }
                        else if (block == BlockType.Diamond)
                        {
                            PlaySoundForEveryoneElse(InfiniminerSound.RadarHigh, new Vector3(x + 0.5f, y + 0.5f, z + 0.5f), player);
                        }

                        if (artifactActive[(byte)blockCreatorTeam[x, y, z], 7] > 0)//reflection artifact
                        {
                            if (player.Health > 2 * artifactActive[(byte)blockCreatorTeam[x, y, z], 7])
                            {
                                player.Health -= (uint)(2 * artifactActive[(byte)blockCreatorTeam[x, y, z], 7]);
                                SendHealthUpdate(player);
                            }
                            else
                            {
                                Player_Dead(player, "BEAT THEMSELVES AGAINST A WALL!");
                            }
                        }
                    }

                    PlaySoundForEveryoneElse(sound, player.Position, player);
                }
                else
                {
                    if (player.Ore > ResearchComplete[(byte)player.Team, 4])//make repairs
                    {
                        Damage = -(2 * ResearchComplete[(byte)player.Team, 4] + 2);
                        //sound = repair?

                        if (blockListHP[x, y, z] >= BlockInformation.GetMaxHP(blockList[x, y, z]))
                        {
                            if (block == BlockType.SolidRed || block == BlockType.SolidBlue)
                            {
                                hitPoint -= playerHeading * 0.3f;
                                player.Ore -= (uint)ResearchComplete[(byte)player.Team, 4] + 1;
                                blockListHP[x, y, z] -= Damage;
                                DebrisEffectAtPoint(hitPoint.X, hitPoint.Y, hitPoint.Z, block, 0);
                                SetBlock(x, y, z, player.Team == PlayerTeam.Red ? BlockType.SolidRed2 : BlockType.SolidBlue2, player.Team);
                                SendOreUpdate(player);
                                PlaySoundForEveryoneElse(sound, player.Position, player);
                            }
                            else if (block == BlockType.ConstructionR && player.Team == PlayerTeam.Red || block == BlockType.ConstructionB && player.Team == PlayerTeam.Blue)//construction complete
                            {
                                SetBlock(x, (ushort)(y + 1), z, player.Team == PlayerTeam.Red ? BlockType.ForceR : BlockType.ForceB, player.Team);
                                SetBlock(x, y, z, (BlockType)blockListContent[x,y,z,0], player.Team);
                                blockListHP[x, y, z] = BlockInformation.GetMaxHP(blockList[x, y, z]);
                            }
                        }
                        else
                        {
                            hitPoint -= playerHeading * 0.3f;
                            player.Ore -= (uint)ResearchComplete[(byte)player.Team, 4] + 1;
                            DebrisEffectAtPoint(hitPoint.X, hitPoint.Y, hitPoint.Z, block, 0);
                            blockListHP[x, y, z] -= Damage;
                            SendOreUpdate(player);
                            PlaySoundForEveryoneElse(sound, player.Position, player);
                        }
                    }
                }
            }
            else
            {//player was out of sync, replace his empty block
                //ConsoleWrite("fixed " + player.Handle + " synchronization");
                SetBlockForPlayer(x, y, z, block, blockCreatorTeam[x, y, z], player);
            }
        }
Esempio n. 2
0
        //private bool LocationNearBase(ushort x, ushort y, ushort z)
        //{
        //    for (int i=0; i<MAPSIZE; i++)
        //        for (int j=0; j<MAPSIZE; j++)
        //            for (int k = 0; k < MAPSIZE; k++)
        //                if (blockList[i, j, k] == BlockType.HomeBlue || blockList[i, j, k] == BlockType.HomeRed)
        //                {
        //                    double dist = Math.Sqrt(Math.Pow(x - i, 2) + Math.Pow(y - j, 2) + Math.Pow(z - k, 2));
        //                    if (dist < 3)
        //                        return true;
        //                }
        //    return false;
        //}
        public void ThrowRope(Player player, Vector3 playerPosition, Vector3 playerHeading)
        {
            bool actionFailed = false;

            if (player.Alive == false || player.playerToolCooldown > DateTime.Now)
            {
                actionFailed = true;
            }
            else if (player.Ore > 49)
            {
                player.Ore -= 50;
                SendOreUpdate(player);
            }
            else
            {
                actionFailed = true;
            }
            // If there's no surface within range, bail.
            Vector3 hitPoint = playerPosition;
            Vector3 buildPoint = playerPosition;
            Vector3 exactPoint = playerPosition;

            ushort x = (ushort)buildPoint.X;
            ushort y = (ushort)buildPoint.Y;
            ushort z = (ushort)buildPoint.Z;

            if (x <= 0 || y <= 0 || z <= 0 || (int)x > MAPSIZE - 1 || (int)y > MAPSIZE - 1 || (int)z > MAPSIZE - 1)
                actionFailed = true;

            if (blockList[(ushort)hitPoint.X, (ushort)hitPoint.Y, (ushort)hitPoint.Z] == BlockType.Lava || blockList[(ushort)hitPoint.X, (ushort)hitPoint.Y, (ushort)hitPoint.Z] == BlockType.Water)
                actionFailed = true;

            if (actionFailed)
            {
                // Decharge the player's gun.
                //    TriggerConstructionGunAnimation(player, -0.2f);
            }
            else
            {
                player.playerToolCooldown = DateTime.Now + TimeSpan.FromSeconds((float)(player.GetToolCooldown(PlayerTools.ThrowRope)));
                // Fire the player's gun.
                //    TriggerConstructionGunAnimation(player, 0.5f);

                // Build the block.
                //hitPoint = RayCollision(playerPosition, playerHeading, 6, 25, ref hitPoint, ref buildPoint, 1);

                exactPoint.Y = exactPoint.Y + (float)0.25;//0.25 = items height

                uint ii = SetItem(ItemType.Rope, exactPoint, playerHeading, playerHeading * 5, player.Team, 0);
                itemList[ii].Content[6] = (byte)player.Team;//set teamsafe
                // player.Ore -= blockCost;
                // SendResourceUpdate(player);

                // Play the sound.
                PlaySound(InfiniminerSound.ConstructionGun, player.Position);
            }
        }