CrabBattleServer.CrabBehavior.GoGoBattleCrab C# (CSharp) Method

GoGoBattleCrab() public method

public GoGoBattleCrab ( ) : void
return void
        public void GoGoBattleCrab()
        {
            if (CurrentTarget == -1)
               CurrentTarget = GameServer.players[0].Id;

            // new code simply makes crab target only players in game basicly
            List<PlayerObject> readyPlayers = GameServer.players.FindAll(p => p.Ready);
            if (readyPlayers.Count == 0) return;

            if (TargetChange.ElapsedMilliseconds > changetick)
            {
                int rnd = random.Next(0, 4);
                if (rnd == 0)
                {
                    changetick = 10000;
                    TargetChange.Restart();
                    int prnd = random.Next(0, readyPlayers.Count);
                    CurrentTarget = readyPlayers[prnd].Id;
                    Console.WriteLine("(id "+CurrentTarget+") Crab is changing targets to "+readyPlayers[prnd].Name);
                }
                else
                    changetick += 1000;
            }

            if (IsPerformingAction)
            {
                if (CurrentAction.ElapsedMilliseconds > ActionLength * 1000)
                {
                    IsPerformingAction = false;
                }
            }

            //CurrentHealth = (int)(1500f - TotalElapsed.ElapsedMilliseconds/100f);

            if (!IsPerformingAction)
            {
                float healthPercent = ((float)CurrentHealth / (float)MaxHealth) * 100f;

                for (int i = 0; i < MajorActions.Count; i++)
                {
                    //Console.WriteLine(MajorActions[i].StartHealth + " " + healthPercent);
                    if (MajorActions[i].StartHealth >= healthPercent)
                    {
                        if (MajorActions[i].HasBeenUsed == false || MajorActions[i].TimeSinceUsage.ElapsedMilliseconds > MajorActions[i].DelayTime * 1000)
                        {
                            Console.WriteLine("Crab health is at " + healthPercent + "% Health (" + CurrentHealth + "/" + MaxHealth + ").");

                            UseCrabAction(MajorActions[i]);
                            break;

                        }
                    }
                }
            }

            if (!IsPerformingAction)
                Console.WriteLine("The crab is not currently performing any actions!!");
        }

Same methods

CrabBehavior::GoGoBattleCrab ( float time, float deltaTime ) : void

Usage Example

Esempio n. 1
0
        public void RunGameLoop()
        {
            Console.WriteLine(" Starting RunGameLoop Thread.");
            //isRunning = true;

            if(playintro == false)
               introlength = new TimeSpan(0, 0, 7);
            else
                introlength = new TimeSpan(0, 0, 21);

            beatrate = new TimeSpan(0, 0, 1);

            introtime = DateTime.Now;
            lastBeat = DateTime.Now;

            NetOutgoingMessage outmsg;

            crab = new CrabBehavior();

            //while(isRunning)
            int sendRate = 1000 / ticksPerSecond; // 1 sec = 1000ms as Sleep uses ms.
            for ( isRunning=true; isRunning; Thread.Sleep(sendRate) )
            {
                if (gamePhase != (int)GameState.Lobby && players.Count == 0)
                {
                    Console.WriteLine("All players disconnected, returning to lobby gamestate.");

                    gamePhase = (int)GameState.Lobby;
                }

                if (gamePhase == (int)GameState.Intro && ((introtime + introlength) < DateTime.Now))
                {
                    //Intro has ran for it's length, lets start the game proper.
                    Console.WriteLine("PlayIntro was set to '"+playintro+"' sending StartGame packet to clients...");
                    //outmsg = server.CreateMessage();
                    //outmsg.Write((byte)PacketTypes.StartGame);
                    //server.SendMessage(outmsg, server.Connections, NetDeliveryMethod.ReliableOrdered, 1);

                    crab.Direction = false;
                    gamePhase = (int)GameState.InGame;
                }

                if(gamePhase == (int)GameState.InGame && crab.CurrentHealth>0)
                {
                    crab.GoGoBattleCrab();
                }

            // Handle dropping players and long idle connections. Note Client must send a KeepAlive packet within 15s
            if (NetTime.Now > last15sec+15)
                {
                    foreach (PlayerObject player in players)
                    {
                        //Console.WriteLine("KeepAlive Check "+player.Name+" (Id"+player.Id+") "+ player.Connection.Status+" RTT "+player.Connection.AverageRoundtripTime +" keepAlive "+player.keepAlive+" vs. lastKeepAlive "+player.lastKeepAlive);
                        if (player.keepAlive > player.lastKeepAlive)
                            player.lastKeepAlive = NetTime.Now;
                        else if (player.keepAlive != player.lastKeepAlive)
                        {
                            SendLobbyMessage("Server","You may need the latest github update v1.1 for multiplayer support.",player.Connection);
                            SendConsoleMessage("You may need the lastest github update v1.1 for multiplayer support.",player.Connection);
                            SendMessageDebug("You may need the lastest github update v1.1 for multiplayer support.",player.Connection);
                            player.Connection.Deny(player.Name + " (Id"+player.Id+") idle connection's keepAlive "+player.keepAlive+" is < lastKeepAlive "+player.lastKeepAlive);
                        }
                        else if (player.keepAlive == player.lastKeepAlive)
                            player.lastKeepAlive = NetTime.Now;
                    }
                    last15sec = NetTime.Now;
                }

                //Send update beats.
                if ((lastBeat + beatrate) < DateTime.Now && gamePhase >=1)
                {
                    //Send a beat to all users. Because the server doesn't really know if they disconnected unless we are sending packets to them.
                    //Beats go out every 2 seconds.
                    foreach (PlayerObject p in players)
                    {
                        outmsg = server.CreateMessage();
                        outmsg.Write((byte)PacketTypes.Beat);
                        outmsg.Write((Int16)beatnum);
                        outmsg.Write(p.Connection.AverageRoundtripTime/2f);
                        server.SendMessage(outmsg, p.Connection, NetDeliveryMethod.ReliableOrdered, 4);
                    }
                    beatnum++;
                    lastBeat = DateTime.Now;
                }
            }
            Console.WriteLine(" Stopped RunGameLoop Thread.");
        }
All Usage Examples Of CrabBattleServer.CrabBehavior::GoGoBattleCrab