Example #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            FileDebug.ClearOrCreateDebugFile();

            // TODO: Add your initialization logic here
            NetMessage NetMsg = new NetMessage();
            NetMsg.PosX = 15;
            NetMsg.PosY = 200;

            cli = new Client("localhost", 1234);
            cli.Connect();

            for (int i = 0; i < 1000; i++)
            {
                cli.SendSerializedMsg(NetMsg);
            }

            //NetMsg.PosX = 1;
            //NetMsg.PosY = 1;

            //cli.SendSerializedMsg(NetMsg);
            //cli.Disconnect();

            base.Initialize();
        }
 private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
 {
     string sendDataStr = "disconnect";
     NetMessage nMsg = new NetMessage(sendDataStr, myUsername, mySecret, client.PublicKey);
     string sendStr = JsonConvert.SerializeObject(nMsg);
     byte[] _unEncBy = sendStr.GetBytes();
     client.SendUnencryptedBytes(_unEncBy); //send
 }
 /// <summary>
 /// Coloca un mensaje en la cola
 /// </summary>
 /// <param name="m">el mensaje a colocar en la cola</param>
 public void put(NetMessage m)
 {
     monitor.Enter();
     queue.Enqueue(m);
     itemCount++;
     monitor.Pulse();
     monitor.Exit();
 }
 /// <summary>
 /// Coloca un mensaje en la cola
 /// </summary>
 /// <param name="m">el mensaje a colocar en la cola</param>
 public void put(NetMessage m)
 {
     lock (this)
     {
         queue.Enqueue(m);
         itemCount++;
         Monitor.Pulse(this);
     }
 }
	public static NetMessage Create (string id, string str1="", string str2="", int val=-1, byte[] bytes=null) {
		NetMessage msg = new NetMessage ();
		msg.id = id;
		msg.str1 = str1;
		msg.str2 = str2;
		msg.val = val;
		msg.bytes = bytes;
		return msg;
	}
Example #6
0
		void OnSetDeck (NetMessage msg) {

			// Wait a frame to ensure that DeckManager sets the deck before referencing it
			Co.WaitForFixedUpdate (() => {
				Game.Dispatcher.ScheduleMessage ("StartGame");
				Co.YieldWhileTrue (() => { return !Game.Controller.DataLoaded; }, () => {
					AllGotoView ("roles");
				});
			});
		}
 internal void SerializeMessage(NetMessage message) {
     if (!NetSerializer.TryWriteMessage(unreliableStream, message)) {
         if (retry) {
             NetLog.Warning("SerializeUnreliableMessage failed.");
             retry = false;
             return;
         }
         // Stream likely full, flush stream and retry serialization:
         retry = true;
         FlushStream();
         SerializeMessage(message);
     }
     if (retry) retry = false;
 }
Example #8
0
	void Run (NetMessage msg) {

		Game.Dispatcher.AddListener ("GotoView", GotoView);

		if (!Hosting)
			return;

		if (Game.Views.CurrView != "lobby") {
			Debug.LogWarning ("Test must begin in the lobby");
			return;
		}

		PressButton ("play");
	}
		void StartTimer (NetMessage msg) {
			
			if (HasElement ("timer")) {

				float duration = msg.str1 == "deliberate"
					? Duration
					: ExtraTimeDuration;

				TimerElement timer = GetScreenElement<TimerElement> ("timer");
				timer.Reset (duration);
				timer.StartTimer ();
			}
			state = State.Extra;
		}
Example #10
0
        public static void EncodeMessage(Session session, NetMessage msg)
        {
            // do some complex encode actions here ...

            Encoding encode = Encoding.UTF8;
            Byte[] bytes = null;

            if (!msg.IsString())
                bytes = msg.RawContent;
            else if (msg.MessageContent.Length > 0)
                bytes = encode.GetBytes(msg.MessageContent);

            if (bytes == null) bytes = new byte[0];

            msg.ContentSize = bytes.Length; // refresh size
            msg.RawContent = bytes; // refresh content
        }
    static int Main(string[] args)
    {
        //TODO: Private Message
        //TODO: Mute

        try
        {
            Console.WriteLine("FlamingApi Client v6.9.7");
            //mySecret = Guid.NewGuid().ToString("N");
            mySecret = "apibotsecretnotasecretanymore";
            //Console.WriteLine("Enter a username:"******"apibot";//Console.ReadLine();
            client.Connect(ep);
            Console.WriteLine("Connecting to server...");
            string sendDataStr = "connect"; //this time, sending a connect command
            //client.Send(("connect:" + Guid.NewGuid().ToString("N")).GetBytes(), "connect".GetBytes().Length);
            string sKeyinb64 = Convert.ToBase64String(client.PublicKey.GetBytes());
            NetMessage nMsg = new NetMessage(sendDataStr, myUsername, mySecret, sKeyinb64);
            string sendStr = JsonConvert.SerializeObject(nMsg);
            byte[] ssBytes = sendStr.GetBytes();

            //client.SendUnencryptedBytes("HANDSHAKE".GetBytes());
            //client.SendUnencryptedBytes(client.PublicKey.GetBytes());
            //client.SetSessionKey(client.ReceiveUnencryptedBytes(ref ep).GetString());

            client.SendUnencryptedBytes(ssBytes); //Send a connect command along with a public key

            byte[] encryptedSessionKey = client.ReceiveUnencryptedBytes(ref ep);
            string sessionKey = client.DecryptBytesWithPrivateKey(encryptedSessionKey).GetString();
            Console.WriteLine("Got session Key: {0}", sessionKey);
            client.SetSessionKey(mySecret, sessionKey);
            if (ReceiveData(true) == "OK") { successfulConnect = true; Console.WriteLine("Connection Established."); }; //OK
            ReceiveData(true); //Welcome Message
            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
        }
        catch (Exception e)
        {
            Console.WriteLine("Error! Server might not be on. Error info: " + e.ToString());
            return -1;
        }
        heartbeatThread.Start();
        senderThread.Start();
        mainCode();
        return 0;
    }
Example #12
0
        public static void DecodeMessage(Session session, NetMessage msg)
        {
            // do some complex decode actions here ...

            Byte[] bytes = msg.RawContent;
            if (bytes == null || bytes.Length <= 0) return; // nothing needs to decode

            if (msg.IsString())
            {
                Encoding encode = Encoding.UTF8;
                if (msg.MessageContent.Length == 0) msg.MessageContent = encode.GetString(bytes, 0, bytes.Length);
                else msg.MessageContent += encode.GetString(bytes, 0, bytes.Length);
            }
            else
            {
                msg.RawContent = bytes;
            }
        }
Example #13
0
 /// <summary>
 /// Sends a message to all connected clients
 /// </summary>
 /// <param name="message">The JSON message to send</param>
 public void SendMessage(NetMessage message)
 {
     _sendDone.WaitOne();
     _sendDone.Reset();
     //byte[] buffer = Encoding.ASCII.GetBytes(message.ToString() + "\u0007");
     byte[] buffer = Encoding.ASCII.GetBytes(message.ToString());
     //MessageBox.Show("Sending " + buffer.Length.ToString() + " chars.");
     try
     {
         foreach (Socket s in ActiveClients)
             s.Send(buffer);
     }
     catch (SocketException)
     {
         //disconnected, will catch elsewhere
     }
     Thread.Sleep(500);
     _sendDone.Set();
 }
Example #14
0
		void RefreshTimer (NetMessage msg) {
			// Game.Controller.SetWinner (msg.str1);
			// GotoView ("winner");
			Debug.Log("RefreshTimer: " + msg.flVal);

			if(timerElPlayer != null) {

				timerElPlayer.Progress = msg.flVal;
				timerElPlayer.Reset(msg.flVal);
				timerElPlayer.StartTimer(msg.flVal);
			
			}
			if(timerElDecider != null) {

				timerElDecider.Progress = msg.flVal;
				timerElDecider.Reset(msg.flVal);
			
			}
		}
        public byte[] Marshall(NetMessage message)
        {
            try{
                Atom thriftMessage = ThriftMessageConverter.translate(message);

                MemoryStream stream = new MemoryStream();
                TProtocol tProtocol = new TBinaryProtocol(new TStreamTransport(stream, stream));

                thriftMessage.Write(tProtocol);

                byte[] data = stream.ToArray();

                return data;
            }catch(Exception ex){
                log.Error("Error marshalling message", ex);
            }

            return null;
        }
Example #16
0
        public void SendMessage(NetMessage message)
        {
            if (string.IsNullOrEmpty(message.data))
            {
                char[] msg = {'E', 'm', 'p', 't', 'y'};
                message.data = new string(msg);
            }

            try
            {
                byte[] typeBytes = BitConverter.GetBytes((int)message.type);
                byte[] dataBytes = _encoding.GetBytes(message.data);
                NetworkStream netstream = _client.GetStream();
                netstream.Write(typeBytes, 0, typeBytes.Length);
                netstream.Write(dataBytes, 0, dataBytes.Length);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Example #17
0
        public bool ConnectToServer(string ip, int port)
        {
            _client = new TcpClient();
            _encoding = new ASCIIEncoding();

            try
            {
                IPAddress address = IPAddress.Parse(ip);
                _client.Connect(address, port);
                NetMessage message = new NetMessage();
                message.type = MessageTypes.ClientHandshake;
                SendMessage(message);
                NetMessage response = ReceiveMessage();
                MessageBox.Show(Resources.Client_ConnectToServer_Server_responded_with_ + response.data);
                return response.type == MessageTypes.ServerHandshakeResponse;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                return false;
            }
        }
	/// <summary>
	/// Called when a player joins or leaves the room that this player is hosting
	/// </summary>
	public void OnUpdatePlayers (NetMessage msg) {

		Dictionary<string, string> playerColors = AvatarsManager.ToDict (msg.str1);

		// Add any players that haven't already been registered
		foreach (var pc in playerColors) {

			string name = pc.Key;
			string color = pc.Value;

			if (players.ContainsKey (name))
				continue;

			players.Add (name, new Player {
				Name = name,
				Avatar = color
			});

			if (onAddPeer != null)
				onAddPeer (name, color);
		}

		// Remove old players that weren't included in the message
		Dictionary<string, Player> temp = new Dictionary<string, Player> (players);

		foreach (var p in temp) {

			string name = p.Key;

			if (!playerColors.ContainsKey (name)) {

				players.Remove (name);

				if (onRemovePeer != null)
					onRemovePeer (name);
			}
		}
	}
	IEnumerator LatentSendConfirmation (NetMessage msg) {
		yield return new WaitForSeconds (Random.value);
		ReceiveMessageEvent (msg);
	}
Example #20
0
        private void PlaceThing(Hook.Player.orig_PlaceThing orig, Player self)
        {
            if (disableMod && IsNetSynced)
            {
                return;
            }
            int createTile = self.HeldItem.createTile;

            if (createTile == TileID.Torches || (TileLoader.GetTile(createTile)?.torch ?? false))
            {
                orig(self);
                return;
            }
            Tile tile  = Main.tile[Player.tileTargetX, Player.tileTargetY];
            Tile tile2 = Main.tile[Player.tileTargetX, Player.tileTargetY + 1];

            if (!tile.active())
            {
                orig(self);
                return;
            }
            ushort oldType       = tile.type;
            ushort wall          = tile2.wall;
            Chest  chest         = null;
            int    targetOffsetX = 0;
            int    targetOffsetY = 0;
            int    targetSizeX   = 0;
            int    targetSizeY   = 0;
            byte   oldSlope      = tile.slope();
            bool   oldHalfBrick  = tile.halfBrick();
            short  oldFrameX     = -1;
            short  oldFrameY     = -1;

            if (Main.tileFrameImportant[tile.type])  //TileID.Sets.Platforms[tile.type]
            {
                oldFrameX = tile.frameX;
                oldFrameY = tile.frameY;
            }
            bool chestSwapping = false;

            if (PlaceThingChecks(self) && createTile > -1 && TileCompatCheck(tile, createTile, self.HeldItem.placeStyle) && tile.active())
            {
                int selected = self.selectedItem;
                if (!(Main.tileAxe[tile.type] || Main.tileHammer[tile.type]))
                {
                    if (Main.tileContainer[tile.type] && Main.tileContainer[createTile])
                    {
                        TileObjectData objectData = TileObjectData.GetTileData(tile.type, 0);
                        int            cIndex     = Chest.FindChest(Player.tileTargetX, Player.tileTargetY - (objectData.Height - 1));
                        if (cIndex != -1)
                        {
                            targetSizeX   = objectData.Width - 1;
                            targetSizeY   = objectData.Height - 1;
                            targetOffsetY = -targetSizeY;
                            if ((IsNetSynced || Main.netMode == 0) && Chest.UsingChest(cIndex) == -1 && !Chest.isLocked(Player.tileTargetX, Player.tileTargetY - 1))
                            {
                                chest = Main.chest[cIndex];
                                chest.y++;
                                chestSwapping = true;
                            }
                            else
                            {
                                orig(self);
                                return;
                            }
                        }
                    }
                    self.selectedItem = GetBestToolSlot(self, out int power, toolType: Pickaxe);
                    if (power <= 0)
                    {
                        orig(self);
                        return;
                    }
                    clientSwapping = true;

                    try {
                        blockKillTileChestCheck = true;
                        if (!chestSwapping)
                        {
                            self.PickTile(Player.tileTargetX, Player.tileTargetY, power);
                        }

                        if (chestSwapping || hitTileLastDamage > 0 || (Sets.Grass[oldType] && tile.type == Dirt))
                        {
                            AchievementsHelper.CurrentlyMining = true;
                            //if(hitID > -1)self.hitTile.Clear(hitID);
                            if (Main.netMode == NetmodeID.MultiplayerClient)
                            {
                                clientSwapping = false;
                            }
                            if (tile.active())
                            {
                                self.PickTile(Player.tileTargetX, Player.tileTargetY, ushort.MaxValue);
                            }
                            if (Main.netMode == NetmodeID.SinglePlayer)
                            {
                                clientSwapping = false;
                            }
                            //WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY);
                            SetWall(tile2);
                            AchievementsHelper.HandleMining();
                            AchievementsHelper.CurrentlyMining = false;
                        }/* else if(!tile.active()) {
                          * SetWall(tile2);
                          * }*/
                        else
                        {
                            self.itemTime = 0;
                            BlockSwapPlayer.triggerItemTime = true;
                        }
                    } finally {
                        blockKillTileChestCheck = false;
                        clientSwapping          = false;
                    }
                }
                self.selectedItem = selected;
            }
            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                if (chestSwapping)
                {
                    int tSX = targetSizeX + 1;
                    int tSY = targetSizeY + 1;
                    int x   = Player.tileTargetX + targetOffsetX;
                    int y   = Player.tileTargetY + targetOffsetY;
                    for (int i = 0; i < tSX; i++)
                    {
                        for (int j = 0; j < tSY; j++)
                        {
                            if (Main.tile[x + i, y + j].type == oldType)
                            {
                                Main.tile[x + i, y + j].type = 0;
                                Main.tile[x + i, y + j].active(false);
                            }
                        }
                    }
                }
                try {
                    blockChestHooks = true;
                    orig(self);
                } finally {
                    blockChestHooks = false;
                }
                if (tile.type != oldType || (Main.tileFrameImportant[tile.type] && (oldFrameX == tile.frameX || oldFrameY == tile.frameY)))
                {
                    tile2.wall = wall;
                    tile.slope(oldSlope);
                    tile.halfBrick(oldHalfBrick);
                    if (TileID.Sets.Platforms[tile.type])
                    {
                        tile.frameX = oldFrameX;
                    }
                    WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY);

                    NetMessage.SendTileRange(Main.myPlayer, Player.tileTargetX + targetOffsetX, Player.tileTargetY + targetOffsetY, targetSizeX, targetSizeY);
                    if (chestSwapping)
                    {
                        targetSizeX++;
                        targetSizeY++;
                        ModPacket packet = GetPacket(1 + (4 * 2) + (targetSizeX * targetSizeY * 3 * 2));
                        packet.Write((byte)0);
                        int x = Player.tileTargetX + targetOffsetX;
                        int y = Player.tileTargetY + targetOffsetY;
                        packet.Write((short)x);
                        packet.Write((short)y);
                        packet.Write((short)targetSizeX);
                        packet.Write((short)targetSizeY);
                        for (int i = 0; i < targetSizeX; i++)
                        {
                            for (int j = 0; j < targetSizeY; j++)
                            {
                                packet.Write(Main.tile[x + i, y + j].type);
                                packet.Write(Main.tile[x + i, y + j].frameX);
                                packet.Write(Main.tile[x + i, y + j].frameY);
                                Main.tile[x + i, y + j].active(true);
                            }
                        }
                        packet.Send();
                    }
                    //NetMessage.SendData(MessageID.TileChange, -1, -1, null, GetTileNetType(tile.type), Player.tileTargetX, Player.tileTargetY);
                }
            }
            else
            {
                orig(self);
                if (tile.type != oldType || (Main.tileFrameImportant[tile.type] && (oldFrameX == tile.frameX || oldFrameY == tile.frameY)))
                {
                    tile2.wall = wall;
                    tile.slope(oldSlope);
                    tile.halfBrick(oldHalfBrick);
                    if (TileID.Sets.Platforms[tile.type])
                    {
                        tile.frameX = oldFrameX;
                    }
                    WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY);
                }
            }

            if (!(chest is null))
            {
                chest.y--;
            }
        }
	// -- Private methods

	/// <summary>
	/// MultiplayerManager calls this when a message is received. Better not to use this in any other context ;)
	/// </summary>
	public void ReceiveMessage (NetMessage msg) {
		#if SIMULATE_LATENCY
			StartCoroutine (LatentSendConfirmation (msg));
		#else
			ReceiveMessageEvent (msg);
		#endif
	}
        void SendStats(NPC npc)
        {
            try
            {
                //System.Console.WriteLine("SendStats");

                StringBuilder sb = new StringBuilder();
                sb.Append("Damage stats for " + Lang.GetNPCNameValue(npc.type) + ": ");
                for (int i = 0; i < 256; i++)
                {
                    int playerDamage = damageDone[i];
                    if (playerDamage > 0)
                    {
                        if (i == 255)
                        {
                            sb.Append($"Traps/TownNPC: {playerDamage}, ");
                        }
                        else
                        {
                            sb.Append($"{Main.player[i].name}: {playerDamage}, ");
                        }
                    }
                }
                sb.Length -= 2;                 // removes last ,
                Color messageColor = Color.Orange;

                if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(sb.ToString()), messageColor);

                    var netMessage = mod.GetPacket();
                    netMessage.Write((byte)DPSExtremeMessageType.InformClientsCurrentBossTotals);
                    netMessage.Write(true);
                    netMessage.Write((byte)npc.whoAmI);
                    DPSExtremeGlobalNPC bossGlobalNPC = npc.GetGlobalNPC <DPSExtremeGlobalNPC>();
                    byte count = 0;
                    for (int i = 0; i < 256; i++)
                    {
                        if (bossGlobalNPC.damageDone[i] > 0)
                        {
                            count++;
                        }
                    }
                    netMessage.Write(count);
                    for (int i = 0; i < 256; i++)
                    {
                        if (bossGlobalNPC.damageDone[i] > 0)
                        {
                            netMessage.Write((byte)i);
                            netMessage.Write(bossGlobalNPC.damageDone[i]);
                        }
                    }
                    netMessage.Send();

                    Dictionary <byte, int> stats = new Dictionary <byte, int>();
                    for (int i = 0; i < 256; i++)
                    {
                        if (bossGlobalNPC.damageDone[i] > -1)
                        {
                            stats[(byte)i] = bossGlobalNPC.damageDone[i];
                        }
                    }
                    DPSExtreme.instance.InvokeOnSimpleBossStats(stats);
                }
                else if (Main.netMode == NetmodeID.SinglePlayer)
                {
                    Main.NewText(sb.ToString(), messageColor);
                }
                else if (Main.netMode == NetmodeID.MultiplayerClient)
                {
                    // MP clients should just wait for message.
                }
            }
            catch (Exception e)
            {
                //ErrorLogger.Log("SendStats" + e.Message);
            }
        }
 /// <summary>
 /// Escucha mensajes UDP recibidos
 /// Si ocurre un error se notifica en errorNetworkingHandler
 /// </summary>
 private void listenUDPMessages()
 {
     try
     {
         while (true)
         {
             IPEndPoint ipEndPoint = new IPEndPoint(tcpAddress, netData.UdpPort);
             byte[] buffer = udpClient.Receive(ref ipEndPoint);
             if (buffer.Length > 4)
             {
                 Int32 size = BitConverter.ToInt32(buffer, 0);
                 if (buffer.Length == 4 + size)
                 {
                     byte[] body = new byte[size];
                     Array.Copy(buffer, 4, body, 0, size);
                     NetMessage message = new NetMessage(body);
                     udpMessageQueue.put(message);
                     ipHandler.putReceibedBytes(buffer.Length);
                 }
             }
         }
     }
     catch (ThreadAbortException e)
     {
         throw e;
     }
     catch (Exception e)
     {
         commHandler.informationNetworkingHandler("UDP WARNING: udp client has stopped!!! " + e.Message);
     }
 }
Example #24
0
 public override void Process(NetMessage msg)
 {
     ValidateAdmin(msg);
 }
 internal void SendToAll(Player except, NetMessage msg, ReliabilityMode reliability)
 {
     _server.SendToAllPlayersExcept(except, msg, reliability);
 }
 public void SetMessage(NetMessageBody msgBody)
 {
     m_msg = new NetMessage(new NetMessageHeader(), msgBody);
 }
Example #27
0
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            VirtuousPlayer modPlayer = player.GetModPlayer <VirtuousPlayer>();

            position  = player.Center + (Main.MouseWorld - player.Center).OfLength(item.width); //The nozzle
            position += position.Perpendicular(10);                                             //Moves it up to be centered
            if (!Collision.CanHit(player.Center, 0, 0, position, 0, 0))
            {
                position = player.Center;   //Resets to the player center if the nozzle is unreachable
            }
            if (player.altFunctionUse == 2) //Right click, absorb
            {
                //A little hack to stop the bugged 1-tick delay between consecutive alternate-uses of a weapon
                if (player.itemAnimation == 1) //Resets the animation so it doesn't return to resting position
                {
                    player.itemAnimation = item.useAnimation;
                }
                if (PlayerInput.Triggers.JustReleased.MouseRight) //Stops the item use manually. Has the secondary effect of only sucking while you're actually clicking
                {
                    player.itemAnimation = 0;
                    return(false);
                }

                if (player.itemAnimation == item.useAnimation - 1)
                {
                    Main.PlaySound(SoundID.Item22, position);                 //Once at the beginning of the animation
                }
                bool sucked = false;                                          //Whether an item has been sucked in this tick

                for (int i = 0; i < Main.maxItems; i++)                       //Cycles through all the items in the world
                {
                    if (Main.item[i].active && IsGobblableItem(Main.item[i])) //Finds a valid item
                    {
                        VirtuousItem targetModItem = Main.item[i].GetGlobalItem <VirtuousItem>();

                        if (Main.item[i].WithinRange(position, 250))                                                                    //Within sucking range
                        {
                            Main.item[i].velocity     -= (Main.item[i].Center - position).OfLength(0.5f);                               //Attracts item towards the nozzle
                            targetModItem.beingGobbled = true;                                                                          //So it can't be picked up

                            if (Main.item[i].WithinRange(position, 15))                                                                 //Absorb range
                            {
                                for (int slot = 0; slot < StorageCapacity; slot++)                                                      //Cycles through the storage
                                {
                                    while (slot < StorageCapacity && modPlayer.GobblerStorage[slot] == Empty && Main.item[i].stack > 0) //If it finds an empty slot, it starts adding items from the item stack into the storage
                                    {
                                        if (!sucked)
                                        {
                                            sucked = true;
                                            Main.PlaySound(SoundID.Item3, position);
                                        }

                                        modPlayer.GobblerStorage[slot] = Main.item[i].type; //Adds the item to the current storage slot
                                        Main.item[i].stack--;                               //Reduces the stack of the item
                                        slot++;                                             //Moves a slot forward
                                        if (Main.item[i].stack == 0)                        //The stack of the item has reached 0
                                        {
                                            Main.item[i].active = false;                    //Kills it
                                            slot = StorageCapacity;                         //Breaks the for loop
                                        }
                                    }
                                }
                            }

                            if (Main.netMode == NetmodeID.MultiplayerClient) //Syncs to multiplayer
                            {
                                NetMessage.SendData(MessageID.SyncItem, -1, -1, null, Main.item[i].whoAmI);
                            }
                        }
                    }
                }
            }

            else //Left click, shoot
            {
                if (player.itemAnimation == item.useAnimation - 1) //Once every animation
                {
                    if (modPlayer.GobblerStorage[BaseSlot] != Empty)     //if there is something in the storage
                    {
                        Item shotItem = modPlayer.GobblerItem(BaseSlot); //For easy access

                        Main.PlaySound(SoundID.Item5, position);

                        bool consume = Main.rand.NextFloat() < ConsumeChance(modPlayer.GobblerItem(BaseSlot));

                        if (shotItem.ammo == AmmoID.Arrow)  //Arrows are shot just fine
                        {
                            Projectile newProj = Projectile.NewProjectileDirect(position, new Vector2(speedX, speedY), shotItem.shoot, ProjGobblerItem.ShotDamage(shotItem, player), ProjGobblerItem.ShotKnockBack(shotItem, player), player.whoAmI);
                            newProj.noDropItem = true; //So the arrows don't drop and make a mess...
                        }
                        else //Shooting the custom projectile that takes the form of any item
                        {
                            int itemType = modPlayer.GobblerStorage[BaseSlot];
                            if (itemType == ItemID.EndlessMusketPouch)
                            {
                                itemType = ItemID.MusketBall;                                                                                                           //Exception
                            }
                            Projectile.NewProjectileDirect(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI, consume ? 1f : 0f, itemType); //Shoots the item

                            if (itemType == ItemID.Arkhalis)                                                                                                            //Ridiculous effect for ridiculous weapon
                            {
                                for (int i = 0; i < 5; i++)
                                {
                                    Projectile.NewProjectileDirect(position, new Vector2(speedX, speedY) * Main.rand.NextFloat(), type, damage, knockBack, player.whoAmI, 0f, itemType);
                                }
                            }
                        }

                        if (consume)
                        {
                            modPlayer.GobblerStorage[BaseSlot] = Empty;        //Clears the item from the storage

                            for (int slot = 0; slot < StorageCapacity; slot++) //Loops through the storage
                            {
                                //Moves the entire array one slot down
                                if (slot < StorageCapacity - 1 && modPlayer.GobblerStorage[slot + 1] != Empty)
                                {
                                    modPlayer.GobblerStorage[slot]     = modPlayer.GobblerStorage[slot + 1];
                                    modPlayer.GobblerStorage[slot + 1] = Empty;
                                }
                                if (modPlayer.GobblerStorage[slot] == Empty)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else //Nothing in the storage
                    {
                        Main.PlaySound(SoundID.Item23, position);
                    }
                }
            }

            return(false); //Doesn't shoot normally
        }
 public NetMessageStream(NetMessageBody msgBody)
 {
     m_msg = new NetMessage(new NetMessageHeader(), msgBody);
 }
        //#####################################################################################

        public void SetMessage(NetMessage msg)
        {
            m_msg = msg;
        }
 public NetMessageStream(NetMessage msg)
 {
     m_msg = msg;
 }
 public NetMessageStream()
 {
     m_msg = new NetMessage();
 }
 public override void Process(NetMessage msg)
 {
     VerifyAdminStatus(msg);
 }
	/**
	 *	Client & Host methods
	 */

	public void SendMessage (NetMessage msg) {

		JSONObject obj;

		if (msg.id == "InstanceDataLoaded") { // Special case
			obj = new JSONObject (msg.str1);
			obj.AddField ("roomId", connection.roomId);
			obj.AddField ("key", msg.id);
		} else {
			obj = JSONObject.Create ();
			obj.AddField ("roomId", connection.roomId);
			obj.AddField ("key", msg.id);
			obj.AddField ("str1", msg.str1);
			obj.AddField ("str2", msg.str2);
			obj.AddField ("val", msg.val);
		}

		Emit ("sendMessage", obj);
	}
        public override void AI()
        {
            if (npc.localAI[1] == 0f)
            {
                npc.localAI[1] = 1f;
                Init();
            }
            if (npc.ai[3] > 0f)
            {
                npc.realLife = (int)npc.ai[3];
            }
            if (!head && npc.timeLeft < 300)
            {
                npc.timeLeft = 300;
            }
            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead)
            {
                npc.TargetClosest(true);
            }
            if (Main.player[npc.target].dead && npc.timeLeft > 300)
            {
                npc.timeLeft = 300;
            }
            if (Main.netMode != 1)
            {
                if (!tail && npc.ai[0] == 0f)
                {
                    if (head)
                    {
                        npc.ai[3]    = (float)npc.whoAmI;
                        npc.realLife = npc.whoAmI;
                        npc.ai[2]    = (float)Main.rand.Next(minLength, maxLength + 1);
                        npc.ai[0]    = (float)NPC.NewNPC((int)(npc.position.X + (float)(npc.width / 2)), (int)(npc.position.Y + (float)npc.height), bodyType, npc.whoAmI);
                    }
                    else if (npc.ai[2] > 0f)
                    {
                        npc.ai[0] = (float)NPC.NewNPC((int)(npc.position.X + (float)(npc.width / 2)), (int)(npc.position.Y + (float)npc.height), npc.type, npc.whoAmI);
                    }
                    else
                    {
                        npc.ai[0] = (float)NPC.NewNPC((int)(npc.position.X + (float)(npc.width / 2)), (int)(npc.position.Y + (float)npc.height), tailType, npc.whoAmI);
                    }
                    Main.npc[(int)npc.ai[0]].ai[3]    = npc.ai[3];
                    Main.npc[(int)npc.ai[0]].realLife = npc.realLife;
                    Main.npc[(int)npc.ai[0]].ai[1]    = (float)npc.whoAmI;
                    Main.npc[(int)npc.ai[0]].ai[2]    = npc.ai[2] - 1f;
                    npc.netUpdate = true;
                }
                if (!head && (!Main.npc[(int)npc.ai[1]].active || (Main.npc[(int)npc.ai[1]].type != headType && Main.npc[(int)npc.ai[1]].type != bodyType)))
                {
                    npc.life = 0;
                    npc.HitEffect(0, 10.0);
                    npc.active = false;
                }
                if (!tail && (!Main.npc[(int)npc.ai[0]].active || (Main.npc[(int)npc.ai[0]].type != bodyType && Main.npc[(int)npc.ai[0]].type != tailType)))
                {
                    npc.life = 0;
                    npc.HitEffect(0, 10.0);
                    npc.active = false;
                }
                if (!npc.active && Main.netMode == 2)
                {
                    NetMessage.SendData(28, -1, -1, null, npc.whoAmI, -1f, 0f, 0f, 0, 0, 0);
                }
            }
            int num180 = (int)(npc.position.X / 16f) - 1;
            int num181 = (int)((npc.position.X + (float)npc.width) / 16f) + 2;
            int num182 = (int)(npc.position.Y / 16f) - 1;
            int num183 = (int)((npc.position.Y + (float)npc.height) / 16f) + 2;

            if (num180 < 0)
            {
                num180 = 0;
            }
            if (num181 > Main.maxTilesX)
            {
                num181 = Main.maxTilesX;
            }
            if (num182 < 0)
            {
                num182 = 0;
            }
            if (num183 > Main.maxTilesY)
            {
                num183 = Main.maxTilesY;
            }
            bool flag18 = flies;

            if (!flag18)
            {
                for (int num184 = num180; num184 < num181; num184++)
                {
                    for (int num185 = num182; num185 < num183; num185++)
                    {
                        if (Main.tile[num184, num185] != null && ((Main.tile[num184, num185].nactive() && (Main.tileSolid[(int)Main.tile[num184, num185].type] || (Main.tileSolidTop[(int)Main.tile[num184, num185].type] && Main.tile[num184, num185].frameY == 0))) || Main.tile[num184, num185].liquid > 64))
                        {
                            Vector2 vector17;
                            vector17.X = (float)(num184 * 16);
                            vector17.Y = (float)(num185 * 16);
                            if (npc.position.X + (float)npc.width > vector17.X && npc.position.X < vector17.X + 16f && npc.position.Y + (float)npc.height > vector17.Y && npc.position.Y < vector17.Y + 16f)
                            {
                                flag18 = true;
                                if (Main.rand.Next(100) == 0 && npc.behindTiles && Main.tile[num184, num185].nactive())
                                {
                                    WorldGen.KillTile(num184, num185, true, true, false);
                                }
                                if (Main.netMode != 1 && Main.tile[num184, num185].type == 2)
                                {
                                    ushort arg_BFCA_0 = Main.tile[num184, num185 - 1].type;
                                }
                            }
                        }
                    }
                }
            }
            if (!flag18 && head)
            {
                Rectangle rectangle = new Rectangle((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height);
                int       num186    = 1000;
                bool      flag19    = true;
                for (int num187 = 0; num187 < 255; num187++)
                {
                    if (Main.player[num187].active)
                    {
                        Rectangle rectangle2 = new Rectangle((int)Main.player[num187].position.X - num186, (int)Main.player[num187].position.Y - num186, num186 * 2, num186 * 2);
                        if (rectangle.Intersects(rectangle2))
                        {
                            flag19 = false;
                            break;
                        }
                    }
                }
                if (flag19)
                {
                    flag18 = true;
                }
            }
            if (directional)
            {
                if (npc.velocity.X < 0f)
                {
                    npc.spriteDirection = 1;
                }
                else if (npc.velocity.X > 0f)
                {
                    npc.spriteDirection = -1;
                }
            }
            float   num188   = speed;
            float   num189   = turnSpeed;
            Vector2 vector18 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
            float   num191   = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2);
            float   num192   = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2);

            num191     = (float)((int)(num191 / 16f) * 16);
            num192     = (float)((int)(num192 / 16f) * 16);
            vector18.X = (float)((int)(vector18.X / 16f) * 16);
            vector18.Y = (float)((int)(vector18.Y / 16f) * 16);
            num191    -= vector18.X;
            num192    -= vector18.Y;
            float num193 = (float)System.Math.Sqrt((double)(num191 * num191 + num192 * num192));

            if (npc.ai[1] > 0f && npc.ai[1] < (float)Main.npc.Length)
            {
                try
                {
                    vector18 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
                    num191   = Main.npc[(int)npc.ai[1]].position.X + (float)(Main.npc[(int)npc.ai[1]].width / 2) - vector18.X;
                    num192   = Main.npc[(int)npc.ai[1]].position.Y + (float)(Main.npc[(int)npc.ai[1]].height / 2) - vector18.Y;
                }
                catch
                {
                }
                npc.rotation = (float)System.Math.Atan2((double)num192, (double)num191) + 1.57f;
                num193       = (float)System.Math.Sqrt((double)(num191 * num191 + num192 * num192));
                int num194 = npc.width;
                num193         = (num193 - (float)num194) / num193;
                num191        *= num193;
                num192        *= num193;
                npc.velocity   = Vector2.Zero;
                npc.position.X = npc.position.X + num191;
                npc.position.Y = npc.position.Y + num192;
                if (directional)
                {
                    if (num191 < 0f)
                    {
                        npc.spriteDirection = 1;
                    }
                    if (num191 > 0f)
                    {
                        npc.spriteDirection = -1;
                    }
                }
            }
            else
            {
                if (!flag18)
                {
                    npc.TargetClosest(true);
                    npc.velocity.Y = npc.velocity.Y + 0.11f;
                    if (npc.velocity.Y > num188)
                    {
                        npc.velocity.Y = num188;
                    }
                    if ((double)(System.Math.Abs(npc.velocity.X) + System.Math.Abs(npc.velocity.Y)) < (double)num188 * 0.4)
                    {
                        if (npc.velocity.X < 0f)
                        {
                            npc.velocity.X = npc.velocity.X - num189 * 1.1f;
                        }
                        else
                        {
                            npc.velocity.X = npc.velocity.X + num189 * 1.1f;
                        }
                    }
                    else if (npc.velocity.Y == num188)
                    {
                        if (npc.velocity.X < num191)
                        {
                            npc.velocity.X = npc.velocity.X + num189;
                        }
                        else if (npc.velocity.X > num191)
                        {
                            npc.velocity.X = npc.velocity.X - num189;
                        }
                    }
                    else if (npc.velocity.Y > 4f)
                    {
                        if (npc.velocity.X < 0f)
                        {
                            npc.velocity.X = npc.velocity.X + num189 * 0.9f;
                        }
                        else
                        {
                            npc.velocity.X = npc.velocity.X - num189 * 0.9f;
                        }
                    }
                }
                else
                {
                    if (!flies && npc.behindTiles && npc.soundDelay == 0)
                    {
                        float num195 = num193 / 40f;
                        if (num195 < 10f)
                        {
                            num195 = 10f;
                        }
                        if (num195 > 20f)
                        {
                            num195 = 20f;
                        }
                        npc.soundDelay = (int)num195;
                        Main.PlaySound(SoundID.Roar, npc.position, 1);
                    }
                    num193 = (float)System.Math.Sqrt((double)(num191 * num191 + num192 * num192));
                    float num196 = System.Math.Abs(num191);
                    float num197 = System.Math.Abs(num192);
                    float num198 = num188 / num193;
                    num191 *= num198;
                    num192 *= num198;
                    if (ShouldRun())
                    {
                        bool flag20 = true;
                        for (int num199 = 0; num199 < 255; num199++)
                        {
                            if (Main.player[num199].active && !Main.player[num199].dead && Main.player[num199].ZoneCorrupt)
                            {
                                flag20 = false;
                            }
                        }
                        if (flag20)
                        {
                            if (Main.netMode != 1 && (double)(npc.position.Y / 16f) > (Main.rockLayer + (double)Main.maxTilesY) / 2.0)
                            {
                                npc.active = false;
                                int num200 = (int)npc.ai[0];
                                while (num200 > 0 && num200 < 200 && Main.npc[num200].active && Main.npc[num200].aiStyle == npc.aiStyle)
                                {
                                    int num201 = (int)Main.npc[num200].ai[0];
                                    Main.npc[num200].active = false;
                                    npc.life = 0;
                                    if (Main.netMode == 2)
                                    {
                                        NetMessage.SendData(23, -1, -1, null, num200, 0f, 0f, 0f, 0, 0, 0);
                                    }
                                    num200 = num201;
                                }
                                if (Main.netMode == 2)
                                {
                                    NetMessage.SendData(23, -1, -1, null, npc.whoAmI, 0f, 0f, 0f, 0, 0, 0);
                                }
                            }
                            num191 = 0f;
                            num192 = num188;
                        }
                    }
                    bool flag21 = false;
                    if (npc.type == 87)
                    {
                        if (((npc.velocity.X > 0f && num191 < 0f) || (npc.velocity.X < 0f && num191 > 0f) || (npc.velocity.Y > 0f && num192 < 0f) || (npc.velocity.Y < 0f && num192 > 0f)) && System.Math.Abs(npc.velocity.X) + System.Math.Abs(npc.velocity.Y) > num189 / 2f && num193 < 300f)
                        {
                            flag21 = true;
                            if (System.Math.Abs(npc.velocity.X) + System.Math.Abs(npc.velocity.Y) < num188)
                            {
                                npc.velocity *= 1.1f;
                            }
                        }
                        if (npc.position.Y > Main.player[npc.target].position.Y || (double)(Main.player[npc.target].position.Y / 16f) > Main.worldSurface || Main.player[npc.target].dead)
                        {
                            flag21 = true;
                            if (System.Math.Abs(npc.velocity.X) < num188 / 2f)
                            {
                                if (npc.velocity.X == 0f)
                                {
                                    npc.velocity.X = npc.velocity.X - (float)npc.direction;
                                }
                                npc.velocity.X = npc.velocity.X * 1.1f;
                            }
                            else
                            {
                                if (npc.velocity.Y > -num188)
                                {
                                    npc.velocity.Y = npc.velocity.Y - num189;
                                }
                            }
                        }
                    }
                    if (!flag21)
                    {
                        if ((npc.velocity.X > 0f && num191 > 0f) || (npc.velocity.X < 0f && num191 < 0f) || (npc.velocity.Y > 0f && num192 > 0f) || (npc.velocity.Y < 0f && num192 < 0f))
                        {
                            if (npc.velocity.X < num191)
                            {
                                npc.velocity.X = npc.velocity.X + num189;
                            }
                            else
                            {
                                if (npc.velocity.X > num191)
                                {
                                    npc.velocity.X = npc.velocity.X - num189;
                                }
                            }
                            if (npc.velocity.Y < num192)
                            {
                                npc.velocity.Y = npc.velocity.Y + num189;
                            }
                            else
                            {
                                if (npc.velocity.Y > num192)
                                {
                                    npc.velocity.Y = npc.velocity.Y - num189;
                                }
                            }
                            if ((double)System.Math.Abs(num192) < (double)num188 * 0.2 && ((npc.velocity.X > 0f && num191 < 0f) || (npc.velocity.X < 0f && num191 > 0f)))
                            {
                                if (npc.velocity.Y > 0f)
                                {
                                    npc.velocity.Y = npc.velocity.Y + num189 * 2f;
                                }
                                else
                                {
                                    npc.velocity.Y = npc.velocity.Y - num189 * 2f;
                                }
                            }
                            if ((double)System.Math.Abs(num191) < (double)num188 * 0.2 && ((npc.velocity.Y > 0f && num192 < 0f) || (npc.velocity.Y < 0f && num192 > 0f)))
                            {
                                if (npc.velocity.X > 0f)
                                {
                                    npc.velocity.X = npc.velocity.X + num189 * 2f;
                                }
                                else
                                {
                                    npc.velocity.X = npc.velocity.X - num189 * 2f;
                                }
                            }
                        }
                        else
                        {
                            if (num196 > num197)
                            {
                                if (npc.velocity.X < num191)
                                {
                                    npc.velocity.X = npc.velocity.X + num189 * 1.1f;
                                }
                                else if (npc.velocity.X > num191)
                                {
                                    npc.velocity.X = npc.velocity.X - num189 * 1.1f;
                                }
                                if ((double)(System.Math.Abs(npc.velocity.X) + System.Math.Abs(npc.velocity.Y)) < (double)num188 * 0.5)
                                {
                                    if (npc.velocity.Y > 0f)
                                    {
                                        npc.velocity.Y = npc.velocity.Y + num189;
                                    }
                                    else
                                    {
                                        npc.velocity.Y = npc.velocity.Y - num189;
                                    }
                                }
                            }
                            else
                            {
                                if (npc.velocity.Y < num192)
                                {
                                    npc.velocity.Y = npc.velocity.Y + num189 * 1.1f;
                                }
                                else if (npc.velocity.Y > num192)
                                {
                                    npc.velocity.Y = npc.velocity.Y - num189 * 1.1f;
                                }
                                if ((double)(System.Math.Abs(npc.velocity.X) + System.Math.Abs(npc.velocity.Y)) < (double)num188 * 0.5)
                                {
                                    if (npc.velocity.X > 0f)
                                    {
                                        npc.velocity.X = npc.velocity.X + num189;
                                    }
                                    else
                                    {
                                        npc.velocity.X = npc.velocity.X - num189;
                                    }
                                }
                            }
                        }
                    }
                }
                npc.rotation = (float)System.Math.Atan2((double)npc.velocity.Y, (double)npc.velocity.X) + 1.57f;
                if (head)
                {
                    if (flag18)
                    {
                        if (npc.localAI[0] != 1f)
                        {
                            npc.netUpdate = true;
                        }
                        npc.localAI[0] = 1f;
                    }
                    else
                    {
                        if (npc.localAI[0] != 0f)
                        {
                            npc.netUpdate = true;
                        }
                        npc.localAI[0] = 0f;
                    }
                    if (((npc.velocity.X > 0f && npc.oldVelocity.X < 0f) || (npc.velocity.X < 0f && npc.oldVelocity.X > 0f) || (npc.velocity.Y > 0f && npc.oldVelocity.Y < 0f) || (npc.velocity.Y < 0f && npc.oldVelocity.Y > 0f)) && !npc.justHit)
                    {
                        npc.netUpdate = true;
                        return;
                    }
                }
            }
            CustomBehavior();
        }
Example #35
0
        public override bool NewRightClick(int i, int j)
        {
            Player player = Main.LocalPlayer;
            Tile   tile   = Main.tile[i, j];

            Main.mouseRightRelease = false;
            int left = i;
            int top  = j;

            if (tile.frameX % 36 != 0)
            {
                left--;
            }
            if (tile.frameY != 0)
            {
                top--;
            }
            if (player.sign >= 0)
            {
                Main.PlaySound(SoundID.MenuClose);
                player.sign      = -1;
                Main.editSign    = false;
                Main.npcChatText = "";
            }
            if (Main.editChest)
            {
                Main.PlaySound(SoundID.MenuTick);
                Main.editChest   = false;
                Main.npcChatText = "";
            }
            if (player.editedChestName)
            {
                NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0);
                player.editedChestName = false;
            }
            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                if (left == player.chestX && top == player.chestY && player.chest >= 0)
                {
                    player.chest = -1;
                    Recipe.FindRecipes();
                    Main.PlaySound(SoundID.MenuClose);
                }
                else
                {
                    NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, top, 0f, 0f, 0, 0, 0);
                    Main.stackSplit = 600;
                }
            }
            else
            {
                int chest = Chest.FindChest(left, top);
                if (chest >= 0)
                {
                    Main.stackSplit = 600;
                    if (chest == player.chest)
                    {
                        player.chest = -1;
                        Main.PlaySound(SoundID.MenuClose);
                    }
                    else
                    {
                        player.chest         = chest;
                        Main.playerInventory = true;
                        Main.recBigList      = false;
                        player.chestX        = left;
                        player.chestY        = top;
                        Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick);
                    }
                    Recipe.FindRecipes();
                }
            }
            return(true);
        }
 static void SendHeartbeats()
 {
     while (true)
     {
         string sendDataStr = "marco";
         sendDataStr = client.EncryptWSessionKey(sendDataStr.GetBytes(), mySecret);
         NetMessage nMsg = new NetMessage(sendDataStr, myUsername, mySecret, client.PublicKey);
         string sendStr = JsonConvert.SerializeObject(nMsg);
         byte[] _sendUnencryptedBytes = sendStr.GetBytes();
         client.SendUnencryptedBytes(_sendUnencryptedBytes);//send
         Thread.Sleep(20000);
     }
 }
 internal void SendPlayerMessage(Player player, NetMessage msg, ReliabilityMode mode, bool recycle)
 {
     _server.SendToPlayer(player, msg, mode, recycle);
 }
 static void TextSenderThreadPoint()
 {
     while (true)
     {
         string sendDataStr = Console.ReadLine();
         if (sendDataStr.StartsWith("/c:"))
         {
             sendDataStr = sendDataStr.Remove(0, 3);
             sendDataStr = client.EncryptWSessionKey(sendDataStr.GetBytes(), mySecret);
             NetMessage nMsg = new NetMessage(sendDataStr, myUsername, mySecret, client.PublicKey);
             string sendStr = JsonConvert.SerializeObject(nMsg);
             byte[] _sendUnencryptedBytes = sendStr.GetBytes();
             client.SendUnencryptedBytes(_sendUnencryptedBytes);//send
             ReceiveData(true);
         }
     }
 }
Example #39
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            ExampleModMessageType msgType = (ExampleModMessageType)reader.ReadByte();

            switch (msgType)
            {
            // This message sent by the server to initialize the Volcano Tremor on clients
            case ExampleModMessageType.SetTremorTime:
                int          tremorTime = reader.ReadInt32();
                ExampleWorld world      = GetModWorld <ExampleWorld>();
                world.VolcanoTremorTime = tremorTime;
                break;

            // This message sent by the server to initialize the Volcano Rubble.
            case ExampleModMessageType.VolcanicRubbleMultiplayerFix:
                int numberProjectiles = reader.ReadInt32();
                for (int i = 0; i < numberProjectiles; i++)
                {
                    int  identity = reader.ReadInt32();
                    bool found    = false;
                    for (int j = 0; j < 1000; j++)
                    {
                        if (Main.projectile[j].owner == 255 && Main.projectile[j].identity == identity && Main.projectile[j].active)
                        {
                            Main.projectile[j].hostile = true;
                            //Main.projectile[j].name = "Volcanic Rubble";
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        Logger.Error("Error: Projectile not found");
                    }
                }
                break;

            case ExampleModMessageType.PuritySpirit:
                if (Main.npc[reader.ReadInt32()].modNPC is PuritySpirit spirit && spirit.npc.active)
                {
                    spirit.HandlePacket(reader);
                }
                break;

            case ExampleModMessageType.HeroLives:
                Player player = Main.player[reader.ReadInt32()];
                int    lives  = reader.ReadInt32();
                player.GetModPlayer <ExamplePlayer>().heroLives = lives;
                if (lives > 0)
                {
                    NetworkText text;
                    if (lives == 1)
                    {
                        text = NetworkText.FromKey("Mods.ExampleMod.LifeLeft", player.name);
                    }
                    else
                    {
                        text = NetworkText.FromKey("Mods.ExampleMod.LivesLeft", player.name, lives);
                    }
                    NetMessage.BroadcastChatMessage(text, new Color(255, 25, 25));
                }
                break;

            // This message syncs ExamplePlayer.exampleLifeFruits
            case ExampleModMessageType.ExamplePlayerSyncPlayer:
                byte          playernumber      = reader.ReadByte();
                ExamplePlayer examplePlayer     = Main.player[playernumber].GetModPlayer <ExamplePlayer>();
                int           exampleLifeFruits = reader.ReadInt32();
                examplePlayer.exampleLifeFruits = exampleLifeFruits;
                examplePlayer.nonStopParty      = reader.ReadBoolean();
                // SyncPlayer will be called automatically, so there is no need to forward this data to other clients.
                break;

            case ExampleModMessageType.NonStopPartyChanged:
                playernumber  = reader.ReadByte();
                examplePlayer = Main.player[playernumber].GetModPlayer <ExamplePlayer>();
                examplePlayer.nonStopParty = reader.ReadBoolean();
                // Unlike SyncPlayer, here we have to relay/forward these changes to all other connected clients
                if (Main.netMode == NetmodeID.Server)
                {
                    var packet = GetPacket();
                    packet.Write((byte)ExampleModMessageType.NonStopPartyChanged);
                    packet.Write(playernumber);
                    packet.Write(examplePlayer.nonStopParty);
                    packet.Send(-1, playernumber);
                }
                break;

            case ExampleModMessageType.ExampleTeleportToStatue:
                if (Main.npc[reader.ReadByte()].modNPC is NPCs.ExamplePerson person && person.npc.active)
                {
                    person.StatueTeleport();
                }
                break;

            default:
                Logger.WarnFormat("ExampleMod: Unknown Message type: {0}", msgType);
                break;
            }
        }
Example #40
0
 private async Task SendToClient(NetMessage msg)
 {
     await this.websocket.SendAsync(msg.ToBytes(), System.Net.WebSockets.WebSocketMessageType.Binary, true, System.Threading.CancellationToken.None);
 }
Example #41
0
        public static bool Meteor(int i, int j)
        {
            if (i < 50 || i > Main.maxTilesX - 50)
            {
                return(false);
            }
            if (j < 50 || j > Main.maxTilesY - 50)
            {
                return(false);
            }
            int       num       = 35;
            Rectangle rectangle = new Rectangle((i - num) * 16, (j - num) * 16, num * 2 * 16, num * 2 * 16);

            for (int k = 0; k < 255; k++)
            {
                if (Main.player[k].active)
                {
                    Rectangle value = new Rectangle((int)(Main.player[k].position.X + Main.player[k].width / 2 - NPC.sWidth / 2 - NPC.safeRangeX), (int)(Main.player[k].position.Y + Main.player[k].height / 2 - NPC.sHeight / 2 - NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2);
                    if (rectangle.Intersects(value))
                    {
                        return(false);
                    }
                }
            }
            for (int l = 0; l < 200; l++)
            {
                if (Main.npc[l].active)
                {
                    Rectangle value2 = new Rectangle((int)Main.npc[l].position.X, (int)Main.npc[l].position.Y, Main.npc[l].width, Main.npc[l].height);
                    if (rectangle.Intersects(value2))
                    {
                        return(false);
                    }
                }
            }
            for (int m = i - num; m < i + num; m++)
            {
                for (int n = j - num; n < j + num; n++)
                {
                    if (Main.tile[m, n].active() && Main.tile[m, n].type == 21)
                    {
                        return(false);
                    }
                }
            }
            num = WorldGen.genRand.Next(17, 23);
            for (int num2 = i - num; num2 < i + num; num2++)
            {
                for (int num3 = j - num; num3 < j + num; num3++)
                {
                    if (num3 > j + Main.rand.Next(-2, 3) - 5)
                    {
                        float num4 = Math.Abs(i - num2);
                        float num5 = Math.Abs(j - num3);
                        float num6 = (float)Math.Sqrt(num4 * num4 + num5 * num5);
                        if (num6 < num * 0.9 + Main.rand.Next(-4, 5))
                        {
                            if (!Main.tileSolid[Main.tile[num2, num3].type])
                            {
                                Main.tile[num2, num3].active(false);
                            }
                            Main.tile[num2, num3].type = (ushort)ModContent.TileType <CometOre>();
                        }
                    }
                }
            }
            num = WorldGen.genRand.Next(8, 14);
            for (int num7 = i - num; num7 < i + num; num7++)
            {
                for (int num8 = j - num; num8 < j + num; num8++)
                {
                    if (num8 > j + Main.rand.Next(-2, 3) - 4)
                    {
                        float num9  = Math.Abs(i - num7);
                        float num10 = Math.Abs(j - num8);
                        float num11 = (float)Math.Sqrt(num9 * num9 + num10 * num10);
                        if (num11 < num * 0.8 + Main.rand.Next(-3, 4))
                        {
                            Main.tile[num7, num8].active(false);
                        }
                    }
                }
            }
            num = WorldGen.genRand.Next(25, 35);
            for (int num12 = i - num; num12 < i + num; num12++)
            {
                for (int num13 = j - num; num13 < j + num; num13++)
                {
                    float num14 = Math.Abs(i - num12);
                    float num15 = Math.Abs(j - num13);
                    float num16 = (float)Math.Sqrt(num14 * num14 + num15 * num15);
                    if (num16 < num * 0.7)
                    {
                        if (Main.tile[num12, num13].type == 5 || Main.tile[num12, num13].type == 32 || Main.tile[num12, num13].type == 352)
                        {
                            WorldGen.KillTile(num12, num13, false, false, false);
                        }
                        Main.tile[num12, num13].liquid = 0;
                    }
                    if (Main.tile[num12, num13].type == (ushort)ModContent.TileType <CometOre>())
                    {
                        if (!WorldGen.SolidTile(num12 - 1, num13) && !WorldGen.SolidTile(num12 + 1, num13) && !WorldGen.SolidTile(num12, num13 - 1) && !WorldGen.SolidTile(num12, num13 + 1))
                        {
                            Main.tile[num12, num13].active(false);
                        }
                        else if ((Main.tile[num12, num13].halfBrick() || Main.tile[num12 - 1, num13].topSlope()) && !WorldGen.SolidTile(num12, num13 + 1))
                        {
                            Main.tile[num12, num13].active(false);
                        }
                    }
                    WorldGen.SquareTileFrame(num12, num13, true);
                    WorldGen.SquareWallFrame(num12, num13, true);
                }
            }
            num = WorldGen.genRand.Next(23, 32);
            for (int num17 = i - num; num17 < i + num; num17++)
            {
                for (int num18 = j - num; num18 < j + num; num18++)
                {
                    if (num18 > j + WorldGen.genRand.Next(-3, 4) - 3 && Main.tile[num17, num18].active() && Main.rand.Next(10) == 0)
                    {
                        float num19 = Math.Abs(i - num17);
                        float num20 = Math.Abs(j - num18);
                        float num21 = (float)Math.Sqrt(num19 * num19 + num20 * num20);
                        if (num21 < num * 0.8)
                        {
                            if (Main.tile[num17, num18].type == 5 || Main.tile[num17, num18].type == 32 || Main.tile[num17, num18].type == 352)
                            {
                                WorldGen.KillTile(num17, num18, false, false, false);
                            }
                            Main.tile[num17, num18].type = (ushort)ModContent.TileType <CometOre>();
                            WorldGen.SquareTileFrame(num17, num18, true);
                        }
                    }
                }
            }
            num = WorldGen.genRand.Next(30, 38);
            for (int num22 = i - num; num22 < i + num; num22++)
            {
                for (int num23 = j - num; num23 < j + num; num23++)
                {
                    if (num23 > j + WorldGen.genRand.Next(-2, 3) && Main.tile[num22, num23].active() && Main.rand.Next(20) == 0)
                    {
                        float num24 = Math.Abs(i - num22);
                        float num25 = Math.Abs(j - num23);
                        float num26 = (float)Math.Sqrt(num24 * num24 + num25 * num25);
                        if (num26 < num * 0.85)
                        {
                            if (Main.tile[num22, num23].type == 5 || Main.tile[num22, num23].type == 32 || Main.tile[num22, num23].type == 352)
                            {
                                WorldGen.KillTile(num22, num23, false, false, false);
                            }
                            Main.tile[num22, num23].type = (ushort)ModContent.TileType <CometOre>();
                            WorldGen.SquareTileFrame(num22, num23, true);
                        }
                    }
                }
            }
            string cometText = "The sky has fallen somewhere in the world";

            if (Main.netMode != NetmodeID.MultiplayerClient)
            {
                BaseUtility.Chat(cometText, new Color(136, 151, 255), true);
            }
            if (Main.netMode != NetmodeID.MultiplayerClient)
            {
                NetMessage.SendTileSquare(-1, i, j, 40, TileChangeType.None);
            }
            return(true);
        }
        protected override ArraySegment<byte> SerializeMessage(Message msg)
        {
            switch (msg.kind)
            {
                case 10:
                {
                    // TODO: optimize further
                    var buf = TakeSectionBuffer ();
                    var sX = (msg.param >> 16) * 200;
                    var sY = (msg.param & 0xffff) * 150;

                    int uncompressed = 0;

                    for (int y = sY; y < sY + 150; y++)
                    {
                        if (CompressionVersion == 1)
                        {
                            uncompressed += buf.TileRowSize (200, sX, y);
                            buf.TileRowCompressed (200, sX, y);
                        }
                        else
                            buf.SendTileRow (200, sX, y);

                    }

                    if (uncompressed > 0)
                    {
                        var c = System.Threading.Interlocked.Add (ref _compressed, buf.Written);
                        var u = System.Threading.Interlocked.Add (ref _uncompressed, uncompressed);
                        ProgramLog.Debug.Log ("Total section compression ratio: {2:0.00}% ({0:0.0}MB -> {1:0.0}MB)", u/1024.0/1024.0, c/1024.0/1024.0, c * 100.0 / u);
                    }

                    sectionBuffer = buf;
                    //ProgramLog.Debug.Log ("{0} @ {1}: Sending section ({2}, {3}) of {4} bytes.", RemoteAddress, assignedSlot, sX, sY, buf.Segment.Count);

                    return buf.Segment;
                }
            }
            return new ArraySegment<byte> ();
        }
Example #43
0
 internal void SendMessage(NetMessage msg, ReliabilityMode mode)
 {
     ImplementationSendMessage(msg, mode);
 }
        public override void Kill(int timeLeft)
        {
            Main.PlaySound(SoundID.Item14, projectile.Center);

            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                return;
            }

            int xPos = (int)projectile.Center.X / 16;
            int yPos = (int)projectile.Center.Y / 16;

            for (int i = -45; i <= 45; i++)
            {
                for (int j = -50; j <= 0; j++)
                {
                    int tileX = xPos + i;
                    int tileY = yPos + j;

                    if (tileX < 0 || tileX > Main.maxTilesX || tileY <= 0 || tileY > Main.maxTilesY)
                    {
                        continue;
                    }

                    Tile tile = Framing.GetTileSafely(tileX, tileY);

                    if (tile.type == TileID.LihzahrdAltar)
                    {
                        continue;
                    }

                    if (tile.wall != WallID.LihzahrdBrickUnsafe)
                    {
                        continue;
                    }

                    //check for chest above this block
                    Tile tileAbove = Framing.GetTileSafely(tileX, tileY - 1);
                    if (TileID.Sets.BasicChest[tileAbove.type])
                    {
                        TileObjectData data = TileObjectData.GetTileData(tileAbove.type, 0);
                        int            x    = tileX - (tile.frameX / 18 % data.Width);
                        int            y    = tileY - 1 - (tile.frameY / 18 % data.Height); //get top left of chest

                        WorldGen.KillTile(x, y);
                        if (Main.netMode == NetmodeID.Server)
                        {
                            NetMessage.SendTileSquare(-1, x, y, 3);
                        }

                        //if couldnt destroy chest, ignore this block
                        if (TileID.Sets.BasicChest[tileAbove.type])
                        {
                            continue;
                        }
                    }

                    if (TileID.Sets.BasicChest[tile.type])
                    {
                        TileObjectData data = TileObjectData.GetTileData(tile.type, 0);
                        int            x    = tileX - tile.frameX / 18 % data.Width;
                        int            y    = tileY - tile.frameY / 18 % data.Height; //get top left of chest

                        WorldGen.KillTile(x, y);                                      //try to kill chest
                        if (Main.netMode == NetmodeID.Server)
                        {
                            NetMessage.SendTileSquare(-1, x, y, 3);
                        }

                        continue;
                    }

                    if (tile.type == TileID.LihzahrdBrick)
                    {
                        tile.inActive(true); //actuate it
                        if (Main.netMode == NetmodeID.Server)
                        {
                            NetMessage.SendTileSquare(-1, tileX, tileY, 1);
                        }

                        continue;
                    }

                    WorldGen.KillTile(tileX, tileY);
                    if (Main.netMode == NetmodeID.Server)
                    {
                        NetMessage.SendTileSquare(-1, tileX, tileY, 1);
                    }
                }
            }
        }
 static void SendRequest(string jRq)
 {
     string sendDataStr = client.EncryptWSessionKey(jRq.GetBytes(), mySecret);
     NetMessage nMsg = new NetMessage(sendDataStr, myUsername, mySecret, client.PublicKey);
     string sendStr = JsonConvert.SerializeObject(nMsg);
     byte[] _sendUnencryptedBytes = sendStr.GetBytes();
     client.SendUnencryptedBytes(_sendUnencryptedBytes);//send
 }
Example #46
0
        public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak)
        {
            Tile tile     = Main.tile[i, j];
            Tile tile2    = Main.tile[i, j - 1];
            Tile tile3    = Main.tile[i, j + 1];
            int  tileType = tile.type;

            if (!WorldGen.noTileActions && tile.active() && (tileType == Type))
            {
                if (Main.netMode == NetmodeID.SinglePlayer)
                {
                    if (tile3 != null && !tile3.active())
                    {
                        bool flag18 = !(tile2.active() && (TileID.Sets.BasicChest[tile2.type] || TileID.Sets.BasicChestFake[tile2.type] || tile2.type == 323 || TileLoader.IsDresser(tile2.type)));
                        if (flag18)
                        {
                            int damage         = 10;
                            int projectileType = 0;
                            if (tileType == Type)
                            {
                                projectileType = mod.ProjectileType("AbyssSandBall");
                                damage         = 0;
                            }
                            tile.ClearTile();
                            int num77 = Projectile.NewProjectile(i * 16 + 8, j * 16 + 8, 0f, 0.41f, projectileType, damage, 0f, Main.myPlayer, 0f, 0f);
                            Main.projectile[num77].ai[0] = 1f;
                            WorldGen.SquareTileFrame(i, j, true);
                        }
                    }
                }
                else if (Main.netMode == NetmodeID.Server && tile3 != null && !tile3.active())
                {
                    bool flag19 = !(tile2.active() && (TileID.Sets.BasicChest[tile2.type] || TileID.Sets.BasicChestFake[tile2.type] || tile2.type == 323 || TileLoader.IsDresser(tile2.type)));
                    if (flag19)
                    {
                        int damage2        = 10;
                        int projectileType = 0;
                        if (tileType == Type)
                        {
                            projectileType = mod.ProjectileType("AbyssSandBall");
                            damage2        = 0;
                        }

                        tile.active(false);
                        bool flag20 = false;
                        for (int m = 0; m < 1000; m++)
                        {
                            if (Main.projectile[m].active && Main.projectile[m].owner == Main.myPlayer && Main.projectile[m].type == projectileType && Math.Abs(Main.projectile[m].timeLeft - 3600) < 60 && Main.projectile[m].Distance(new Vector2(i * 16 + 8, j * 16 + 10)) < 4f)
                            {
                                flag20 = true;
                                break;
                            }
                        }
                        if (!flag20)
                        {
                            int num79 = Projectile.NewProjectile(i * 16 + 8, j * 16 + 8, 0f, 2.5f, projectileType, damage2, 0f, Main.myPlayer, 0f, 0f);
                            Main.projectile[num79].velocity.Y = 0.5f;
                            Projectile expr_7AAA_cp_0 = Main.projectile[num79];
                            expr_7AAA_cp_0.position.Y       += 2f;
                            Main.projectile[num79].netUpdate = true;
                        }
                        NetMessage.SendTileSquare(-1, i, j, 1, TileChangeType.None);
                        WorldGen.SquareTileFrame(i, j, true);
                    }
                }
            }
            return(true);
        }
Example #47
0
        public async Task OnRecv(System.IO.MemoryStream stream, int recvcount)
        {
            var p    = stream.Position;
            var msg  = NetMessage.Unpack(stream);
            var pend = stream.Position;

            if (pend - p > recvcount)
            {
                throw new Exception("error net message.");
            }

            var iddata = msg.Params["_id"];

            if (iddata.Length != 8)
            {
                throw new Exception("error net message _id");
            }

            switch (msg.Cmd)
            {
            case "_ping":
                await OnPing(msg, iddata);

                break;

            case "_db.state":
                await OnDB_State(msg, iddata);

                break;

            ///snapshot interface
            case "_db.usesnapshot":
                await OnDB_UseSnapShot(msg, iddata);

                break;

            case "_db.unusesnapshot":
                await OnDB_UnuseSnapShot(msg, iddata);

                break;

            case "_db.snapshot.dataheight":
                await OnSnapshotDataHeight(msg, iddata);    //ulong DataHeight { get; }

                break;

            case "_db.snapshot.getvalue":
                await OnSnapshot_GetValue(msg, iddata);    //DBValue GetValue(byte[] tableid, byte[] key);

                break;

            case "_db.snapshot.gettableinfo":
                await OnSnapshot_GetTableInfo(msg, iddata);    //TableInfo GetTableInfo(byte[] tableid);

                break;

            case "_db.snapshot.gettablecount":
                await OnSnapshot_GetTableCount(msg, iddata);     //uint GetTableCount(byte[] tableid);

                break;

            case "_db.snapshot.newiterator":
                await OnSnapshot_CreateKeyIterator(msg, iddata);     //CreateKeyIterator(byte[] tableid, byte[] _beginkey = null, byte[] _endkey = null);

                break;

            case "_db.iterator.current":
                await OnSnapshot_IteratorCurrent(msg, iddata);     //CreateKeyIterator(byte[] tableid, byte[] _beginkey = null, byte[] _endkey = null);

                break;

            case "_db.iterator.next":
                await OnSnapshot_IteratorNext(msg, iddata);     //CreateKeyIterator(byte[] tableid, byte[] _beginkey = null, byte[] _endkey = null);

                break;

            case "_db.iterator.reset":
                await OnSnapshot_IteratorReset(msg, iddata);     //CreateKeyIterator(byte[] tableid, byte[] _beginkey = null, byte[] _endkey = null);

                break;

            ///write method
            case "_db.write":
                await OnDB_Write(msg, iddata);

                break;

            //要扩展几个东西,直接获取block信息和blockhash,获取有写入权限的地址
            case "_db.snapshot.getblock":
                await OnSnapshotEXT_GetBlock(msg, iddata);

                break;

            case "_db.snapshot.getblockhash":
                await OnSnapshotEXT_GetBlockHash(msg, iddata);

                break;

            case "_db.snapshot.getwriter":
                await OnSnapshotEXT_GetWriter(msg, iddata);

                break;

            //还需要扩展,查询的时候,一次返回多个的
            //case "_db.iteratorex.nextmulti":
            default:
                throw new Exception("unknown msg cmd:" + msg.Cmd);
            }
        }
        public override void RightClick(int i, int j)
        {
            Player player = Main.LocalPlayer;

            if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameY == 0)
            {
                Main.CancelClothesWindow(true);
                Main.mouseRightRelease = false;
                int left = (int)(Main.tile[Player.tileTargetX, Player.tileTargetY].frameX / 18);
                left %= 3;
                left  = Player.tileTargetX - left;
                int top = Player.tileTargetY - (int)(Main.tile[Player.tileTargetX, Player.tileTargetY].frameY / 18);
                if (player.sign > -1)
                {
                    Main.PlaySound(SoundID.MenuClose);
                    player.sign      = -1;
                    Main.editSign    = false;
                    Main.npcChatText = string.Empty;
                }
                if (Main.editChest)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    Main.editChest   = false;
                    Main.npcChatText = string.Empty;
                }
                if (player.editedChestName)
                {
                    NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0);
                    player.editedChestName = false;
                }
                if (Main.netMode == 1)
                {
                    if (left == player.chestX && top == player.chestY && player.chest != -1)
                    {
                        player.chest = -1;
                        Recipe.FindRecipes();
                        Main.PlaySound(SoundID.MenuClose);
                    }
                    else
                    {
                        NetMessage.SendData(31, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0);
                        Main.stackSplit = 600;
                    }
                }
                else
                {
                    player.flyingPigChest = -1;
                    int num213 = Chest.FindChest(left, top);
                    if (num213 != -1)
                    {
                        Main.stackSplit = 600;
                        if (num213 == player.chest)
                        {
                            player.chest = -1;
                            Recipe.FindRecipes();
                            Main.PlaySound(SoundID.MenuClose);
                        }
                        else if (num213 != player.chest && player.chest == -1)
                        {
                            player.chest         = num213;
                            Main.playerInventory = true;
                            Main.recBigList      = false;
                            Main.PlaySound(SoundID.MenuOpen);
                            player.chestX = left;
                            player.chestY = top;
                        }
                        else
                        {
                            player.chest         = num213;
                            Main.playerInventory = true;
                            Main.recBigList      = false;
                            Main.PlaySound(SoundID.MenuTick);
                            player.chestX = left;
                            player.chestY = top;
                        }
                        Recipe.FindRecipes();
                    }
                }
            }
            else
            {
                Main.playerInventory = false;
                player.chest         = -1;
                Recipe.FindRecipes();
                Main.dresserX = Player.tileTargetX;
                Main.dresserY = Player.tileTargetY;
                Main.OpenClothesWindow();
            }
        }
 protected void FreeSectionBuffer()
 {
     if (sectionBuffer != null)
     {
         var buf = sectionBuffer;
         sectionBuffer = null;
         FreeSectionBuffer (buf);
     }
 }
        public override void Explosion()    // This is a special explosive, ignored
        {
            //if (Main.player[projectile.owner].EE().BombardEmblem) return;
            Vector2 position = projectile.position;
            int     width    = 240; //Width of arena
            int     height   = 120; //Height of arena

            int x = 0;
            int y = 0;

            int platformCntr = height - 15; //Space between platform layers

            for (x = -(width / 2); x <= width / 2; x++)
            {
                for (y = height - 1; y >= 0; y--)
                {
                    int xPosition = (int)(x + position.X / 16.0f);
                    int yPosition = (int)(-y + position.Y / 16.0f);

                    if (!WorldGen.InWorld(xPosition, yPosition))
                    {
                        continue;
                    }

                    Tile tile = Framing.GetTileSafely(xPosition, yPosition);

                    if (WorldGen.InWorld(xPosition, yPosition) && tile.active())
                    {
                        if (!CanBreakTile(tile.type, PickPower)) //Unbreakable CheckForUnbreakableTiles(tile) ||
                        {
                        }
                        else //Breakable
                        {
                            if (!TileID.Sets.BasicChest[Main.tile[xPosition, yPosition - 1].type] && !TileLoader.IsDresser(Main.tile[xPosition, yPosition - 1].type) && Main.tile[xPosition, yPosition - 1].type != 26)
                            {
                                tile.ClearTile();
                                tile.active(false);
                            }

                            if (Main.netMode == NetmodeID.MultiplayerClient)
                            {
                                WorldGen.SquareTileFrame(xPosition, yPosition, true); //Updates Area
                                NetMessage.SendData(MessageID.TileChange, -1, -1, null, 2, (float)xPosition, (float)yPosition, 0f, 0, 0, 0);
                            }

                            if (CanBreakWalls)
                            {
                                WorldGen.KillWall(xPosition, yPosition, false);                //This destroys Walls
                            }
                        }
                    }

                    //The following happens whether the block is breakable or not as the following methods cannot break or replace blocks that already exist.
                    if (!OutOfBounds(xPosition, yPosition))
                    {
                        //Breaks Liquid
                        Main.tile[xPosition, yPosition].liquid = Tile.Liquid_Water;
                        WorldGen.SquareTileFrame(xPosition, yPosition, true);

                        //Place Arena Outline
                        if (y == 0 || y == height - 1)
                        {
                            WorldGen.PlaceTile(xPosition, yPosition, TileID.CrystalBlock);
                        }
                        if ((x == -(width / 2) || x == (width / 2)) && (y != 0 || y != height - 1))
                        {
                            WorldGen.PlaceTile(xPosition, yPosition, TileID.CrystalBlock);
                        }

                        //Places Arena Platforms
                        if (y == platformCntr && (x != -(width / 2) || x != (width / 2)))
                        {
                            WorldGen.PlaceTile(xPosition, yPosition, TileID.Platforms);
                            platformCntr -= 15;
                        }
                    }
                }
                platformCntr = height - 15; //Decrease the platformCntr
            }
            platformCntr = 15;              //Reset the platformCntr

            //Now that the space has been cleared and an outline has been established, the arena can be filled.
            for (x = -(width / 2); x < width / 2; x++)
            {
                for (y = 0; y < height; y++)
                {
                    int xPosition = (int)(x + position.X / 16.0f);
                    int yPosition = (int)(-y + position.Y / 16.0f);

                    if (!OutOfBounds(xPosition, yPosition))
                    {
                        //Campfires
                        if (y == platformCntr && (x != -(width / 2) || x != (width / 2)))
                        {
                            if (x == -64 || x == 0 || x == 64)
                            {
                                WorldGen.PlaceTile(xPosition, yPosition - 1, TileID.Campfire);
                            }

                            platformCntr += 30;
                        }
                    }
                }
                platformCntr = 15; //Reset the platformCntr
            }
            platformCntr = 15;     //Reset the platformCntr

            //More arena filling
            for (x = -(width / 2); x < width / 2; x++)
            {
                for (y = 0; y < height; y++)
                {
                    int xPosition = (int)(x + position.X / 16.0f);
                    int yPosition = (int)(-y + position.Y / 16.0f);

                    if (!OutOfBounds(xPosition, yPosition))
                    {
                        //Torches
                        if (y == platformCntr && (x != -(width / 2) || x != (width / 2)))
                        {
                            if (x == -112 || x == -100 || x == -88 || x == -76 || x == -52 || x == -40 || x == -28 || x == -16 || x == -4 || x == 4 || x == 16 || x == 28 || x == 40 || x == 52 || x == 76 || x == 88 || x == 100 || x == 112)
                            {
                                WorldGen.PlaceTile(xPosition, yPosition - 1, TileID.Torches);
                            }

                            platformCntr += 15;
                        }
                    }
                }
                platformCntr = 15;
            }

            //More arena filling
            for (x = -(width / 2); x < width / 2; x++)
            {
                for (y = 0; y < height; y++)
                {
                    int xPosition = (int)(x + position.X / 16.0f);
                    int yPosition = (int)(-y + position.Y / 16.0f);

                    if (!OutOfBounds(xPosition, yPosition))
                    {
                        //Spawn & Nurse
                        if (x > 99)    //X confines
                        {
                            if (y < 7) //Y confines
                            {
                                //Walls
                                if (x == 100 && (y == 4 || y == 5))
                                {
                                    WorldGen.PlaceTile(xPosition, yPosition, TileID.CrystalBlock);
                                }
                                if (x == 109 && (y == 4 || y == 5))
                                {
                                    WorldGen.PlaceTile(xPosition, yPosition, TileID.CrystalBlock);
                                }

                                //Roof
                                if (y == 6 && (x != 100 || x != 120))
                                {
                                    WorldGen.PlaceTile(xPosition, yPosition, TileID.CrystalBlock);
                                }

                                //Background
                                if (x > 100 && x < 120)
                                {
                                    //Break Walls
                                    WorldGen.KillWall(xPosition, yPosition);

                                    //Places Walls
                                    if (y == 5 || y == 2 || y == 1)
                                    {
                                        WorldGen.PlaceWall(xPosition, yPosition, WallID.Wood);
                                    }
                                    if (y == 3 || y == 4)
                                    {
                                        if (x == 113 || x == 114 || x == 115)
                                        {
                                            WorldGen.PlaceWall(xPosition, yPosition, WallID.Glass);
                                        }
                                        else
                                        {
                                            WorldGen.PlaceWall(xPosition, yPosition, WallID.Wood);
                                        }
                                    }
                                }

                                //Lights
                                if (y == 5)
                                {
                                    if (x == 101 || x == 108 || x == 110 || x == 119)
                                    {
                                        WorldGen.PlaceTile(xPosition, yPosition, TileID.Torches);
                                    }
                                }

                                //Furniture
                                if (y == 1)
                                {
                                    if (x == 105)
                                    {
                                        WorldGen.PlaceTile(xPosition, yPosition, TileID.Beds);
                                    }
                                    else if (x == 114)
                                    {
                                        WorldGen.PlaceTile(xPosition, yPosition, TileID.Tables);
                                    }
                                    else if (x == 116)
                                    {
                                        WorldGen.PlaceTile(xPosition, yPosition, TileID.Chairs);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //More arena filling
            for (x = -(width / 2); x < width / 2; x++)
            {
                for (y = 0; y < height; y++)
                {
                    int xPosition = (int)(x + position.X / 16.0f);
                    int yPosition = (int)(-y + position.Y / 16.0f);

                    if (!OutOfBounds(xPosition, yPosition))
                    {
                        //Spawn & Nurse additional
                        if (x > 99)    //X confines
                        {
                            if (y < 7) //Y confines
                            {
                                //Doors
                                if (y == 1)
                                {
                                    if (x == 100)
                                    {
                                        WorldGen.PlaceTile(xPosition, yPosition, TileID.ClosedDoor);
                                    }
                                    else if (x == 109)
                                    {
                                        WorldGen.PlaceTile(xPosition, yPosition, TileID.ClosedDoor);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 static void FreeSectionBuffer(NetMessage buf)
 {
     buf.Clear();
     lock (sectionPool)
         sectionPool.Push (buf);
 }
Example #52
0
        public static void Ghost(CommandArgs args)
        {
            if (args.Parameters.Count == 0)
            {
                int tempTeam = args.Player.TPlayer.team;
                args.Player.TPlayer.team = 0;
                NetMessage.SendData(45, -1, -1, "", args.Player.Index);
                args.Player.TPlayer.team = tempTeam;

                var player = Utils.GetPlayers(args.Player.Index);

                args.Player.SendSuccessMessage(string.Format("Ghost mode {0}tivated"),
                                               player.isGhost ? "ac" : "deac");
                if (args.Parameters.Count > 1)
                {
                    bool silent;

                    if (bool.TryParse(args.Parameters[0], out silent))
                    {
                        if (!silent)
                        {
                            TSPlayer.All.SendInfoMessage(string.Format("{0} {1}"),
                                                         args.Player.Name, player.isGhost ? "left" : "has joined.");
                        }
                    }
                }


                player.isGhost = !player.isGhost;
                args.Player.TPlayer.position.X = 0;
                args.Player.TPlayer.position.Y = 0;
                MAC.cansend = true;
                NetMessage.SendData(13, -1, -1, "", args.Player.Index);
                MAC.cansend = false;
            }
            else
            {
                string str = "";
                for (int i = 0; i < args.Parameters.Count; i++)
                {
                    if (i != args.Parameters.Count - 1)
                    {
                        str += args.Parameters[i] + " ";
                    }
                    else
                    {
                        str += args.Parameters[i];
                    }
                }

                var playerList = TShockAPI.TShock.Utils.FindPlayer(str);

                if (playerList.Count > 1)
                {
                    List <string> foundPlayers = new List <string>();
                    foreach (TSPlayer player in playerList)
                    {
                        foundPlayers.Add(player.Name);
                    }
                    TShock.Utils.SendMultipleMatchError(args.Player, foundPlayers);
                }

                else if (playerList.Count < 1)
                {
                    args.Player.SendErrorMessage(playerList.Count.ToString() + " players matched.");
                }

                else
                {
                    TSPlayer Player   = playerList[0];
                    int      tempTeam = Player.TPlayer.team;
                    Player.TPlayer.team = 0;
                    NetMessage.SendData(45, -1, -1, "", Player.Index);
                    Player.TPlayer.team = tempTeam;
                    var Mplayer = Utils.GetPlayers(Player.Index);

                    args.Player.SendSuccessMessage(string.Format("Ghost mode {0}tivated for {1}.",
                                                                 Mplayer.isGhost ? "ac" : "deac", Mplayer.name));

                    Player.SendInfoMessage(string.Format("{0} has {1}tivated ghost mode on you",
                                                         args.Player.Name, Mplayer.isGhost ? "ac" : "deac"));

                    Mplayer.isGhost           = !Mplayer.isGhost;
                    Player.TPlayer.position.X = 0;
                    Player.TPlayer.position.Y = 0;
                    MAC.cansend = true;
                    NetMessage.SendData(13, -1, -1, "", Player.Index);
                    MAC.cansend = false;
                }
            }
        }
	void ReceiveMessageEvent (NetMessage msg) {
		Dictionary<OnReceiveMessage, string> tempListeners = new Dictionary<OnReceiveMessage, string> (listeners);
		foreach (var listener in tempListeners) {
			if (listener.Value == msg.id)
				listener.Key (msg);
		}
	}
Example #54
0
        public override bool PreAI()
        {
            bool collision = false;

            if (collision)
            {
                if (npc.localAI[0] != 1)
                {
                    npc.netUpdate = true;
                }
                npc.localAI[0] = 1f;
            }
            else
            {
                if (npc.localAI[0] != 0.0)
                {
                    npc.netUpdate = true;
                }
                npc.localAI[0] = 0.0f;
            }
            if ((npc.velocity.X > 0.0 && npc.oldVelocity.X < 0.0 || npc.velocity.X < 0.0 && npc.oldVelocity.X > 0.0 || (npc.velocity.Y > 0.0 && npc.oldVelocity.Y < 0.0 || npc.velocity.Y < 0.0 && npc.oldVelocity.Y > 0.0)) && !npc.justHit)
            {
                npc.netUpdate = true;
            }
            chaosBall++;
            int DustID2 = Dust.NewDust(npc.position, npc.width, npc.height, mod.DustType("CosmicDust"), npc.velocity.X * 0.2f, npc.velocity.Y * 0.2f, 20, default(Color), 1f);

            Main.dust[DustID2].noGravity = true;
            {
                if (Main.player[npc.target].dead)
                {
                    npc.timeLeft = 0;
                }
                if (npc.ai[3] > 0)
                {
                    npc.realLife = (int)npc.ai[3];
                }
                if (npc.target < 0 || npc.target == byte.MaxValue || Main.player[npc.target].dead)
                {
                    npc.TargetClosest(true);
                }
                if (Main.player[npc.target].dead && npc.timeLeft > 300)
                {
                    npc.timeLeft = 300;
                }

                if (Main.netMode != 1)
                {
                    if (!Main.npc[(int)npc.ai[1]].active)
                    {
                        npc.life = 0;
                        npc.HitEffect(0, 10.0);
                        npc.active = false;
                        NetMessage.SendData(28, -1, -1, null, npc.whoAmI, -1f, 0.0f, 0.0f, 0, 0, 0);
                    }
                }

                if (npc.ai[1] < (double)Main.npc.Length)
                {
                    // We're getting the center of this NPC.
                    Vector2 npcCenter = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
                    // Then using that center, we calculate the direction towards the 'parent NPC' of this NPC.
                    float dirX = Main.npc[(int)npc.ai[1]].position.X + (float)(Main.npc[(int)npc.ai[1]].width / 2) - npcCenter.X;
                    float dirY = Main.npc[(int)npc.ai[1]].position.Y + (float)(Main.npc[(int)npc.ai[1]].height / 2) - npcCenter.Y;
                    // We then use Atan2 to get a correct rotation towards that parent NPC.
                    npc.rotation = (float)Math.Atan2(dirY, dirX) + 1.57f;
                    // We also get the length of the direction vector.
                    float length = (float)Math.Sqrt(dirX * dirX + dirY * dirY);
                    // We calculate a new, correct distance.
                    float dist = (length - (float)npc.width) / length;
                    float posX = dirX * dist;
                    float posY = dirY * dist;

                    // Reset the velocity of this NPC, because we don't want it to move on its own
                    npc.velocity = Vector2.Zero;
                    // And set this NPCs position accordingly to that of this NPCs parent NPC.
                    npc.position.X = npc.position.X + posX;
                    npc.position.Y = npc.position.Y + posY;
                }
                return(false);
            }
        }
	/// <summary>
	/// Sends a message to all clients
	/// </summary>
	/// <param name="msg">The NetMessage to send</param>
	public void ScheduleMessage (NetMessage msg) {
		Game.Multiplayer.SendMessageToClients (msg);
		ReceiveMessageEvent (msg);
	}
Example #56
0
        public override void AI()
        {
            Player player     = Main.player[npc.target];
            bool   expertMode = Main.expertMode;

            Lighting.AddLight((int)((npc.position.X + (float)(npc.width / 2)) / 16f), (int)((npc.position.Y + (float)(npc.height / 2)) / 16f), 0f, 0.0375f * 2, 0.125f * 2);
            if (npc.ai[3] > 0f)
            {
                npc.realLife = (int)npc.ai[3];
            }

            if (npc.target < 0 || npc.target == 255 || player.dead)
            {
                npc.TargetClosest(true);
            }

            if (npc.alpha != 0)
            {
                for (int num934 = 0; num934 < 2; num934++)
                {
                    int num935 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 226, 0f, 0f, 100, default(Color), 1f);
                    Main.dust[num935].noGravity = true;
                    Main.dust[num935].noLight   = true;
                }
            }
            npc.alpha -= 12;
            if (npc.alpha < 0)
            {
                npc.alpha = 0;
            }

            if (Main.netMode != 1)
            {
                if (!tail && npc.ai[0] == 0f)
                {
                    int current = npc.whoAmI;
                    for (int num36 = 0; num36 < maxLength; num36++)
                    {
                        int trailing = 0;
                        if (num36 >= 0 && num36 < minLength)
                        {
                            trailing = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), ModContent.NPCType <CogTrapperBody>(), npc.whoAmI);
                        }
                        else
                        {
                            trailing = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), ModContent.NPCType <CogTrapperTail>(), npc.whoAmI);
                        }
                        Main.npc[trailing].realLife = npc.whoAmI;
                        Main.npc[trailing].ai[2]    = (float)npc.whoAmI;
                        Main.npc[trailing].ai[1]    = (float)current;
                        Main.npc[current].ai[0]     = (float)trailing;
                        npc.netUpdate = true;
                        current       = trailing;
                    }
                    tail = true;
                }

                if (!npc.active && Main.netMode == 2)
                {
                    NetMessage.SendData(28, -1, -1, null, npc.whoAmI, -1f, 0f, 0f, 0, 0, 0);
                }
            }

            int num180 = (int)(npc.position.X / 16f) - 1;
            int num181 = (int)((npc.position.X + (float)npc.width) / 16f) + 2;
            int num182 = (int)(npc.position.Y / 16f) - 1;
            int num183 = (int)((npc.position.Y + (float)npc.height) / 16f) + 2;

            if (num180 < 0)
            {
                num180 = 0;
            }
            if (num181 > Main.maxTilesX)
            {
                num181 = Main.maxTilesX;
            }
            if (num182 < 0)
            {
                num182 = 0;
            }
            if (num183 > Main.maxTilesY)
            {
                num183 = Main.maxTilesY;
            }

            bool flag94 = flies;

            npc.localAI[1] = 0f;
            if (directional)
            {
                if (npc.velocity.X < 0f)
                {
                    npc.spriteDirection = 1;
                }
                else if (npc.velocity.X > 0f)
                {
                    npc.spriteDirection = -1;
                }
            }

            if (player.dead)
            {
                npc.TargetClosest(false);
                flag94         = false;
                npc.velocity.Y = npc.velocity.Y + 10f;
                if ((double)npc.position.Y > Main.worldSurface * 16.0)
                {
                    npc.velocity.Y = npc.velocity.Y + 10f;
                }
                if ((double)npc.position.Y > Main.rockLayer * 16.0)
                {
                    for (int num957 = 0; num957 < 200; num957++)
                    {
                        if (Main.npc[num957].aiStyle == npc.aiStyle)
                        {
                            Main.npc[num957].active = false;
                        }
                    }
                }
            }

            float   num188   = speed;
            float   num189   = turnSpeed;
            Vector2 vector18 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
            float   num191   = player.position.X + (float)(player.width / 2);
            float   num192   = player.position.Y + (float)(player.height / 2);
            int     num42    = -1;
            int     num43    = (int)(player.Center.X / 16f);
            int     num44    = (int)(player.Center.Y / 16f);

            for (int num45 = num43 - 2; num45 <= num43 + 2; num45++)
            {
                for (int num46 = num44; num46 <= num44 + 15; num46++)
                {
                    if (WorldGen.SolidTile2(num45, num46))
                    {
                        num42 = num46;
                        break;
                    }
                }
                if (num42 > 0)
                {
                    break;
                }
            }
            if (num42 > 0)
            {
                npc.defense = 5;
                num42      *= 16;
                float num47 = (float)(num42 - 200); //was 800
                if (player.position.Y > num47)
                {
                    num192 = num47;
                    if (Math.Abs(npc.Center.X - player.Center.X) < 125f) //was 500
                    {
                        if (npc.velocity.X > 0f)
                        {
                            num191 = player.Center.X + 150f; //was 600
                        }
                        else
                        {
                            num191 = player.Center.X - 150f; //was 600
                        }
                    }
                }
            }
            else
            {
                npc.defense = 0;
                num188      = expertMode ? 10.83f : 8.66f;  //added 2.5
                num189      = expertMode ? 0.208f : 0.166f; //added 0.05
            }

            float num48 = num188 * 1.5f;
            float num49 = num188 * 0.8f;
            float num50 = npc.velocity.Length();

            if (num50 > 0f)
            {
                if (num50 > num48)
                {
                    npc.velocity.Normalize();
                    npc.velocity *= num48;
                }
                else if (num50 < num49)
                {
                    npc.velocity.Normalize();
                    npc.velocity *= num49;
                }
            }

            if (num42 > 0)
            {
                for (int num51 = 0; num51 < 200; num51++)
                {
                    if (Main.npc[num51].active && Main.npc[num51].type == npc.type && num51 != npc.whoAmI)
                    {
                        Vector2 vector3 = Main.npc[num51].Center - npc.Center;
                        if (vector3.Length() < 400f)
                        {
                            vector3.Normalize();
                            vector3 *= 1000f;
                            num191  -= vector3.X;
                            num192  -= vector3.Y;
                        }
                    }
                }
            }
            else
            {
                for (int num52 = 0; num52 < 200; num52++)
                {
                    if (Main.npc[num52].active && Main.npc[num52].type == npc.type && num52 != npc.whoAmI)
                    {
                        Vector2 vector4 = Main.npc[num52].Center - npc.Center;
                        if (vector4.Length() < 60f)
                        {
                            vector4.Normalize();
                            vector4 *= 200f;
                            num191  -= vector4.X;
                            num192  -= vector4.Y;
                        }
                    }
                }
            }

            num191     = (float)((int)(num191 / 16f) * 16);
            num192     = (float)((int)(num192 / 16f) * 16);
            vector18.X = (float)((int)(vector18.X / 16f) * 16);
            vector18.Y = (float)((int)(vector18.Y / 16f) * 16);
            num191    -= vector18.X;
            num192    -= vector18.Y;
            float num193 = (float)System.Math.Sqrt((double)(num191 * num191 + num192 * num192));

            if (npc.ai[1] > 0f && npc.ai[1] < (float)Main.npc.Length)
            {
                try {
                    vector18 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
                    num191   = Main.npc[(int)npc.ai[1]].position.X + (float)(Main.npc[(int)npc.ai[1]].width / 2) - vector18.X;
                    num192   = Main.npc[(int)npc.ai[1]].position.Y + (float)(Main.npc[(int)npc.ai[1]].height / 2) - vector18.Y;
                } catch {
                }
                npc.rotation = (float)System.Math.Atan2((double)num192, (double)num191) + 1.57f;
                num193       = (float)System.Math.Sqrt((double)(num191 * num191 + num192 * num192));
                int num194 = npc.width;
                num193         = (num193 - (float)num194) / num193;
                num191        *= num193;
                num192        *= num193;
                npc.velocity   = Vector2.Zero;
                npc.position.X = npc.position.X + num191;
                npc.position.Y = npc.position.Y + num192;
                if (directional)
                {
                    if (num191 < 0f)
                    {
                        npc.spriteDirection = 1;
                    }
                    if (num191 > 0f)
                    {
                        npc.spriteDirection = -1;
                    }
                }
            }
            else
            {
                num193 = (float)System.Math.Sqrt((double)(num191 * num191 + num192 * num192));
                float num196 = System.Math.Abs(num191);
                float num197 = System.Math.Abs(num192);
                float num198 = num188 / num193;
                num191 *= num198;
                num192 *= num198;
                bool flag21 = false;
                if (!flag21)
                {
                    if ((npc.velocity.X > 0f && num191 > 0f) || (npc.velocity.X < 0f && num191 < 0f) || (npc.velocity.Y > 0f && num192 > 0f) || (npc.velocity.Y < 0f && num192 < 0f))
                    {
                        if (npc.velocity.X < num191)
                        {
                            npc.velocity.X = npc.velocity.X + num189;
                        }
                        else if (npc.velocity.X > num191)
                        {
                            npc.velocity.X = npc.velocity.X - num189;
                        }

                        if (npc.velocity.Y < num192)
                        {
                            npc.velocity.Y = npc.velocity.Y + num189;
                        }
                        else if (npc.velocity.Y > num192)
                        {
                            npc.velocity.Y = npc.velocity.Y - num189;
                        }

                        if ((double)System.Math.Abs(num192) < (double)num188 * 0.2 && ((npc.velocity.X > 0f && num191 < 0f) || (npc.velocity.X < 0f && num191 > 0f)))
                        {
                            if (npc.velocity.Y > 0f)
                            {
                                npc.velocity.Y = npc.velocity.Y + num189 * 2f;
                            }
                            else
                            {
                                npc.velocity.Y = npc.velocity.Y - num189 * 2f;
                            }
                        }

                        if ((double)System.Math.Abs(num191) < (double)num188 * 0.2 && ((npc.velocity.Y > 0f && num192 < 0f) || (npc.velocity.Y < 0f && num192 > 0f)))
                        {
                            if (npc.velocity.X > 0f)
                            {
                                npc.velocity.X = npc.velocity.X + num189 * 2f; //changed from 2
                            }
                            else
                            {
                                npc.velocity.X = npc.velocity.X - num189 * 2f; //changed from 2
                            }
                        }
                    }
                    else
                    {
                        if (num196 > num197)
                        {
                            if (npc.velocity.X < num191)
                            {
                                npc.velocity.X = npc.velocity.X + num189 * 1.1f; //changed from 1.1
                            }
                            else if (npc.velocity.X > num191)
                            {
                                npc.velocity.X = npc.velocity.X - num189 * 1.1f; //changed from 1.1
                            }
                            if ((double)(System.Math.Abs(npc.velocity.X) + System.Math.Abs(npc.velocity.Y)) < (double)num188 * 0.5)
                            {
                                if (npc.velocity.Y > 0f)
                                {
                                    npc.velocity.Y = npc.velocity.Y + num189;
                                }
                                else
                                {
                                    npc.velocity.Y = npc.velocity.Y - num189;
                                }
                            }
                        }
                        else
                        {
                            if (npc.velocity.Y < num192)
                            {
                                npc.velocity.Y = npc.velocity.Y + num189 * 1.1f;
                            }
                            else if (npc.velocity.Y > num192)
                            {
                                npc.velocity.Y = npc.velocity.Y - num189 * 1.1f;
                            }

                            if ((double)(System.Math.Abs(npc.velocity.X) + System.Math.Abs(npc.velocity.Y)) < (double)num188 * 0.5)
                            {
                                if (npc.velocity.X > 0f)
                                {
                                    npc.velocity.X = npc.velocity.X + num189;
                                }
                                else
                                {
                                    npc.velocity.X = npc.velocity.X - num189;
                                }
                            }
                        }
                    }
                }
            }
            npc.rotation = (float)System.Math.Atan2((double)npc.velocity.Y, (double)npc.velocity.X) + 1.57f;
        }
Example #57
0
        public static void UpdateItem(Item thisItem, int i)
        {
            if (Main.itemLockoutTime[i] > 0)
            {
                Main.itemLockoutTime[i]--;
                return;
            }

            if (!thisItem.active)
            {
                return;
            }
            if (thisItem.instanced)
            {
                if (Main.netMode == NetmodeID.Server)
                {
                    thisItem.active = false;
                    return;
                }
                thisItem.keepTime = 600;
            }
            if (Main.netMode == NetmodeID.SinglePlayer)
            {
                thisItem.owner = Main.myPlayer;
            }
            float num  = 0.1f;
            float num2 = 7f;

            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                int num3 = (int)(thisItem.position.X + (float)(thisItem.width / 2)) / 16;
                int num4 = (int)(thisItem.position.Y + (float)(thisItem.height / 2)) / 16;
                if (num3 >= 0 && num4 >= 0 && num3 < Main.maxTilesX && num4 < Main.maxTilesY && Main.tile[num3, num4] == null)
                {
                    num = 0f;
                    thisItem.velocity.X = 0f;
                    thisItem.velocity.Y = 0f;
                }
            }
            if (thisItem.honeyWet)
            {
                num  = 0.05f;
                num2 = 3f;
            }
            else if (thisItem.wet)
            {
                num2 = 5f;
                num  = 0.08f;
            }
            if (thisItem.ownTime > 0)
            {
                thisItem.ownTime--;
            }
            else
            {
                thisItem.ownIgnore = -1;
            }
            if (thisItem.keepTime > 0)
            {
                thisItem.keepTime--;
            }
            if (thisItem.beingGrabbed)
            {
                thisItem.isBeingGrabbed = true;
            }
            else
            {
                thisItem.isBeingGrabbed = false;
            }
            Vector2 vector = thisItem.velocity * 0.5f;

            if (!thisItem.beingGrabbed)
            {
                bool flag = true;
                if (thisItem.type - 71 <= 3)
                {
                    flag = false;
                }
                if (ItemID.Sets.NebulaPickup[thisItem.type])
                {
                    flag = false;
                }
                if (thisItem.owner == Main.myPlayer && flag && (thisItem.createTile >= TileID.Dirt || thisItem.createWall > 0 || (thisItem.ammo > 0 && !thisItem.notAmmo) || thisItem.consumable || thisItem.type >= ItemID.EmptyBucket && thisItem.type <= ItemID.LavaBucket || thisItem.type == ItemID.HoneyBucket || thisItem.type == ItemID.Wire || thisItem.dye > 0 || thisItem.paint > 0 || thisItem.material) && thisItem.stack < thisItem.maxStack)
                {
                    for (int j = i + 1; j < 400; j++)
                    {
                        if (Main.item[j].active && thisItem.IsTheSameAs(Main.item[j]) && Main.item[j].stack > 0 && Main.item[j].owner == thisItem.owner && Math.Abs(thisItem.position.X + (float)(thisItem.width / 2) - (Main.item[j].position.X + (float)(Main.item[j].width / 2))) + Math.Abs(thisItem.position.Y + (float)(thisItem.height / 2) - (Main.item[j].position.Y + (float)(Main.item[j].height / 2))) < 30f)
                        {
                            thisItem.position = (thisItem.position + Main.item[j].position) / 2f;
                            thisItem.velocity = (thisItem.velocity + Main.item[j].velocity) / 2f;
                            int num5 = Main.item[j].stack;
                            if (num5 > thisItem.maxStack - thisItem.stack)
                            {
                                num5 = thisItem.maxStack - thisItem.stack;
                            }
                            Main.item[j].stack -= num5;
                            thisItem.stack     += num5;
                            if (Main.item[j].stack <= 0)
                            {
                                Main.item[j].SetDefaults(0, false);
                                Main.item[j].active = false;
                            }
                            if (Main.netMode != NetmodeID.SinglePlayer && thisItem.owner == Main.myPlayer)
                            {
                                NetMessage.SendData(MessageID.SyncItem, -1, -1, null, i, 0f, 0f, 0f, 0, 0, 0);
                                NetMessage.SendData(MessageID.SyncItem, -1, -1, null, j, 0f, 0f, 0f, 0, 0, 0);
                            }
                        }
                    }
                }
                if (Main.netMode != NetmodeID.Server && Main.expertMode && thisItem.owner == Main.myPlayer && thisItem.type >= ItemID.CopperCoin && thisItem.type <= ItemID.PlatinumCoin)
                {
                    Rectangle rectangle = new Rectangle((int)thisItem.position.X, (int)thisItem.position.Y, thisItem.width, thisItem.height);
                    for (int k = 0; k < 200; k++)
                    {
                        if (Main.npc[k].active && Main.npc[k].lifeMax > 5 && !Main.npc[k].friendly && !Main.npc[k].immortal && !Main.npc[k].dontTakeDamage)
                        {
                            float num6 = (float)thisItem.stack;
                            float num7 = 1f;
                            if (thisItem.type == ItemID.SilverCoin)
                            {
                                num7 = 100f;
                            }
                            if (thisItem.type == ItemID.GoldCoin)
                            {
                                num7 = 10000f;
                            }
                            if (thisItem.type == ItemID.PlatinumCoin)
                            {
                                num7 = 1000000f;
                            }
                            num6 *= num7;
                            float extraValue = Main.npc[k].extraValue;
                            int   num8       = Main.npc[k].realLife;
                            if (num8 >= 0 && Main.npc[num8].active)
                            {
                                extraValue = Main.npc[num8].extraValue;
                            }
                            else
                            {
                                num8 = -1;
                            }
                            if (extraValue < num6)
                            {
                                Rectangle rectangle2 = new Rectangle((int)Main.npc[k].position.X, (int)Main.npc[k].position.Y, Main.npc[k].width, Main.npc[k].height);
                                if (rectangle.Intersects(rectangle2))
                                {
                                    float num9 = (float)Main.rand.Next(50, 76) * 0.01f;
                                    if (thisItem.type == ItemID.CopperCoin)
                                    {
                                        num9 += (float)Main.rand.Next(51) * 0.01f;
                                    }
                                    if (thisItem.type == ItemID.SilverCoin)
                                    {
                                        num9 += (float)Main.rand.Next(26) * 0.01f;
                                    }
                                    if (num9 > 1f)
                                    {
                                        num9 = 1f;
                                    }
                                    int num10 = (int)((float)thisItem.stack * num9);
                                    if (num10 < 1)
                                    {
                                        num10 = 1;
                                    }
                                    if (num10 > thisItem.stack)
                                    {
                                        num10 = thisItem.stack;
                                    }
                                    thisItem.stack -= num10;
                                    float num11 = (float)num10 * num7;
                                    int   num12 = k;
                                    if (num8 >= 0)
                                    {
                                        num12 = num8;
                                    }
                                    Main.npc[num12].extraValue += num11;
                                    if (Main.netMode == NetmodeID.SinglePlayer)
                                    {
                                        Main.npc[num12].moneyPing(thisItem.position);
                                    }
                                    else
                                    {
                                        NetMessage.SendData(MessageID.SyncExtraValue, -1, -1, null, num12, num11, thisItem.position.X, thisItem.position.Y, 0, 0, 0);
                                    }
                                    if (thisItem.stack <= 0)
                                    {
                                        thisItem.SetDefaults(0, false);
                                        thisItem.active = false;
                                    }
                                    NetMessage.SendData(MessageID.SyncItem, -1, -1, null, i, 0f, 0f, 0f, 0, 0, 0);
                                }
                            }
                        }
                    }
                }
                ItemLoader.Update(thisItem, ref num, ref num2);
                if (ItemID.Sets.ItemNoGravity[thisItem.type])
                {
                    thisItem.velocity.X = thisItem.velocity.X * 0.95f;
                    if ((double)thisItem.velocity.X < 0.1 && (double)thisItem.velocity.X > -0.1)
                    {
                        thisItem.velocity.X = 0f;
                    }
                    thisItem.velocity.Y = thisItem.velocity.Y * 0.95f;
                    if ((double)thisItem.velocity.Y < 0.1 && (double)thisItem.velocity.Y > -0.1)
                    {
                        thisItem.velocity.Y = 0f;
                    }
                }
                else
                {
                    thisItem.velocity.Y = thisItem.velocity.Y + num;
                    if (thisItem.velocity.Y > num2)
                    {
                        thisItem.velocity.Y = num2;
                    }
                    thisItem.velocity.X = thisItem.velocity.X * 0.95f;
                    if ((double)thisItem.velocity.X < 0.1 && (double)thisItem.velocity.X > -0.1)
                    {
                        thisItem.velocity.X = 0f;
                    }
                }
                bool flag2 = Collision.LavaCollision(thisItem.position, thisItem.width, thisItem.height);
                if (flag2)
                {
                    thisItem.lavaWet = true;
                }
                bool flag3 = Collision.WetCollision(thisItem.position, thisItem.width, thisItem.height);
                if (Collision.honey)
                {
                    thisItem.honeyWet = true;
                }
                if (flag3)
                {
                    if (!thisItem.wet)
                    {
                        if (thisItem.wetCount == 0)
                        {
                            thisItem.wetCount = 20;
                            if (!flag2)
                            {
                                if (thisItem.honeyWet)
                                {
                                    for (int l = 0; l < 5; l++)
                                    {
                                        int  num13 = Dust.NewDust(new Vector2(thisItem.position.X - 6f, thisItem.position.Y + (float)(thisItem.height / 2) - 8f), thisItem.width + 12, 24, 152, 0f, 0f, 0, default(Color), 1f);
                                        Dust dust  = Main.dust[num13];
                                        dust.velocity.Y = dust.velocity.Y - 1f;
                                        Dust dust2 = Main.dust[num13];
                                        dust2.velocity.X           = dust2.velocity.X * 2.5f;
                                        Main.dust[num13].scale     = 1.3f;
                                        Main.dust[num13].alpha     = 100;
                                        Main.dust[num13].noGravity = true;
                                    }
                                    Main.PlaySound(SoundID.Splash, (int)thisItem.position.X, (int)thisItem.position.Y, 1, 1f, 0f);
                                }
                                else
                                {
                                    for (int m = 0; m < 10; m++)
                                    {
                                        int  num14 = Dust.NewDust(new Vector2(thisItem.position.X - 6f, thisItem.position.Y + (float)(thisItem.height / 2) - 8f), thisItem.width + 12, 24, Dust.dustWater(), 0f, 0f, 0, default(Color), 1f);
                                        Dust dust3 = Main.dust[num14];
                                        dust3.velocity.Y = dust3.velocity.Y - 4f;
                                        Dust dust4 = Main.dust[num14];
                                        dust4.velocity.X           = dust4.velocity.X * 2.5f;
                                        Main.dust[num14].scale    *= 0.8f;
                                        Main.dust[num14].alpha     = 100;
                                        Main.dust[num14].noGravity = true;
                                    }
                                    Main.PlaySound(SoundID.Splash, (int)thisItem.position.X, (int)thisItem.position.Y, 1, 1f, 0f);
                                }
                            }
                            else
                            {
                                for (int n = 0; n < 5; n++)
                                {
                                    int  num15 = Dust.NewDust(new Vector2(thisItem.position.X - 6f, thisItem.position.Y + (float)(thisItem.height / 2) - 8f), thisItem.width + 12, 24, 35, 0f, 0f, 0, default(Color), 1f);
                                    Dust dust5 = Main.dust[num15];
                                    dust5.velocity.Y = dust5.velocity.Y - 1.5f;
                                    Dust dust6 = Main.dust[num15];
                                    dust6.velocity.X           = dust6.velocity.X * 2.5f;
                                    Main.dust[num15].scale     = 1.3f;
                                    Main.dust[num15].alpha     = 100;
                                    Main.dust[num15].noGravity = true;
                                }
                                Main.PlaySound(SoundID.Splash, (int)thisItem.position.X, (int)thisItem.position.Y, 1, 1f, 0f);
                            }
                        }
                        thisItem.wet = true;
                    }
                }
                else if (thisItem.wet)
                {
                    thisItem.wet = false;
                    byte wetCount = thisItem.wetCount;
                }
                if (!thisItem.wet)
                {
                    thisItem.lavaWet  = false;
                    thisItem.honeyWet = false;
                }
                if (thisItem.wetCount > 0)
                {
                    thisItem.wetCount -= 1;
                }
                if (thisItem.wet)
                {
                    if (thisItem.wet)
                    {
                        Vector2 velocity = thisItem.velocity;
                        thisItem.velocity = Collision.TileCollision(thisItem.position, thisItem.velocity, thisItem.width, thisItem.height, false, false, 1);
                        if (thisItem.velocity.X != velocity.X)
                        {
                            vector.X = thisItem.velocity.X;
                        }
                        if (thisItem.velocity.Y != velocity.Y)
                        {
                            vector.Y = thisItem.velocity.Y;
                        }
                    }
                }
                else
                {
                    thisItem.velocity = Collision.TileCollision(thisItem.position, thisItem.velocity, thisItem.width, thisItem.height, false, false, 1);
                }
                Vector4 vector2 = Collision.SlopeCollision(thisItem.position, thisItem.velocity, thisItem.width, thisItem.height, num, false);
                thisItem.position.X = vector2.X;
                thisItem.position.Y = vector2.Y;
                thisItem.velocity.X = vector2.Z;
                thisItem.velocity.Y = vector2.W;
                Collision.StepConveyorBelt(thisItem, 1f);
                if (thisItem.lavaWet)
                {
                    if (thisItem.type == ItemID.GuideVoodooDoll)
                    {
                        if (Main.netMode != NetmodeID.MultiplayerClient)
                        {
                            thisItem.active = false;
                            thisItem.type   = ItemID.None;
                            thisItem.stack  = 0;
                            for (int num16 = 0; num16 < 200; num16++)
                            {
                                if (Main.npc[num16].active && Main.npc[num16].type == NPCID.Guide)
                                {
                                    if (Main.netMode == NetmodeID.Server)
                                    {
                                        NetMessage.SendData(MessageID.StrikeNPC, -1, -1, null, num16, 9999f, 10f, -(float)Main.npc[num16].direction, 0, 0, 0);
                                    }
                                    Main.npc[num16].StrikeNPCNoInteraction(9999, 10f, -Main.npc[num16].direction, false, false, false);
                                    NPC.SpawnWOF(thisItem.position);
                                }
                            }
                            NetMessage.SendData(MessageID.SyncItem, -1, -1, null, i, 0f, 0f, 0f, 0, 0, 0);
                        }
                    }
                    else if (thisItem.owner == Main.myPlayer && thisItem.type != ItemID.FireblossomSeeds && thisItem.type != ItemID.Fireblossom && thisItem.type != ItemID.Obsidian && thisItem.type != ItemID.Hellstone && thisItem.type != ItemID.HellstoneBar && thisItem.type != ItemID.LivingFireBlock && thisItem.rare == ItemRarityID.White || ItemLoader.CanBurnInLava(thisItem))
                    {
                        thisItem.active = false;
                        thisItem.type   = ItemID.None;
                        thisItem.stack  = 0;
                        if (Main.netMode != NetmodeID.SinglePlayer)
                        {
                            NetMessage.SendData(MessageID.SyncItem, -1, -1, null, i, 0f, 0f, 0f, 0, 0, 0);
                        }
                    }
                }
                if (thisItem.type == ItemID.EnchantedNightcrawler)
                {
                    float num17 = (float)Main.rand.Next(90, 111) * 0.01f;
                    num17 *= (Main.essScale + 0.5f) / 2f;
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.3f * num17, 0.1f * num17, 0.25f * num17);
                }
                else if (thisItem.type == ItemID.SoulofLight || thisItem.type == ItemID.NebulaPickup2)
                {
                    float num18 = (float)Main.rand.Next(90, 111) * 0.01f;
                    num18 *= Main.essScale;
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.5f * num18, 0.1f * num18, 0.25f * num18);
                }
                else if (thisItem.type == ItemID.SoulofNight || thisItem.type == ItemID.NebulaPickup3)
                {
                    float num19 = (float)Main.rand.Next(90, 111) * 0.01f;
                    num19 *= Main.essScale;
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.25f * num19, 0.1f * num19, 0.5f * num19);
                }
                else if (thisItem.type == ItemID.SoulofFright || thisItem.type == ItemID.NebulaPickup1)
                {
                    float num20 = (float)Main.rand.Next(90, 111) * 0.01f;
                    num20 *= Main.essScale;
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.5f * num20, 0.3f * num20, 0.05f * num20);
                }
                else if (thisItem.type == ItemID.SoulofMight)
                {
                    float num21 = (float)Main.rand.Next(90, 111) * 0.01f;
                    num21 *= Main.essScale;
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.1f * num21, 0.1f * num21, 0.6f * num21);
                }
                else if (thisItem.type == ItemID.SoulofFlight)
                {
                    float num22 = (float)Main.rand.Next(90, 111) * 0.01f;
                    num22 *= Main.essScale;
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.1f * num22, 0.3f * num22, 0.5f * num22);
                }
                else if (thisItem.type == ItemID.SoulofSight)
                {
                    float num23 = (float)Main.rand.Next(90, 111) * 0.01f;
                    num23 *= Main.essScale;
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.1f * num23, 0.5f * num23, 0.2f * num23);
                }
                else if (thisItem.type == ItemID.Heart || thisItem.type == ItemID.CandyApple || thisItem.type == ItemID.CandyCane)
                {
                    float num24 = (float)Main.rand.Next(90, 111) * 0.01f;
                    num24 *= Main.essScale * 0.5f;
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.5f * num24, 0.1f * num24, 0.1f * num24);
                }
                else if (thisItem.type == ItemID.Star || thisItem.type == ItemID.SoulCake || thisItem.type == ItemID.SugarPlum)
                {
                    float num25 = (float)Main.rand.Next(90, 111) * 0.01f;
                    num25 *= Main.essScale * 0.5f;
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.1f * num25, 0.1f * num25, 0.5f * num25);
                }
                else if (thisItem.type == ItemID.CursedFlame)
                {
                    float num26 = (float)Main.rand.Next(90, 111) * 0.01f;
                    num26 *= Main.essScale * 0.2f;
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.5f * num26, 1f * num26, 0.1f * num26);
                }
                else if (thisItem.type == ItemID.Ichor)
                {
                    float num27 = (float)Main.rand.Next(90, 111) * 0.01f;
                    num27 *= Main.essScale * 0.2f;
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 1f * num27, 1f * num27, 0.1f * num27);
                }
                else if (thisItem.type == ItemID.FragmentVortex)
                {
                    Lighting.AddLight(thisItem.Center, new Vector3(0.2f, 0.4f, 0.5f) * Main.essScale);
                }
                else if (thisItem.type == ItemID.FragmentNebula)
                {
                    Lighting.AddLight(thisItem.Center, new Vector3(0.4f, 0.2f, 0.5f) * Main.essScale);
                }
                else if (thisItem.type == ItemID.FragmentSolar)
                {
                    Lighting.AddLight(thisItem.Center, new Vector3(0.5f, 0.4f, 0.2f) * Main.essScale);
                }
                else if (thisItem.type == ItemID.FragmentStardust)
                {
                    Lighting.AddLight(thisItem.Center, new Vector3(0.2f, 0.2f, 0.5f) * Main.essScale);
                }
                if (thisItem.type == ItemID.FallenStar && Main.dayTime)
                {
                    for (int num28 = 0; num28 < 10; num28++)
                    {
                        Dust.NewDust(thisItem.position, thisItem.width, thisItem.height, 15, thisItem.velocity.X, thisItem.velocity.Y, 150, default(Color), 1.2f);
                    }
                    for (int num29 = 0; num29 < 3; num29++)
                    {
                        Gore.NewGore(thisItem.position, new Vector2(thisItem.velocity.X, thisItem.velocity.Y), Main.rand.Next(16, 18), 1f);
                    }
                    thisItem.active = false;
                    thisItem.type   = ItemID.None;
                    thisItem.stack  = 0;
                    if (Main.netMode == NetmodeID.Server)
                    {
                        NetMessage.SendData(MessageID.SyncItem, -1, -1, null, i, 0f, 0f, 0f, 0, 0, 0);
                    }
                }
                if (thisItem.type == ItemID.DD2EnergyCrystal && !DD2Event.Ongoing)
                {
                    int num30 = Main.rand.Next(18, 24);
                    for (int num31 = 0; num31 < num30; num31++)
                    {
                        int num32 = Dust.NewDust(thisItem.Center, 0, 0, 61, 0f, 0f, 0, default(Color), 1.7f);
                        Main.dust[num32].velocity *= 8f;
                        Dust dust7 = Main.dust[num32];
                        dust7.velocity.Y           = dust7.velocity.Y - 1f;
                        Main.dust[num32].position  = Vector2.Lerp(Main.dust[num32].position, thisItem.Center, 0.5f);
                        Main.dust[num32].noGravity = true;
                        Main.dust[num32].noLight   = true;
                    }
                    thisItem.active = false;
                    thisItem.type   = ItemID.None;
                    thisItem.stack  = 0;
                    if (Main.netMode == NetmodeID.Server)
                    {
                        NetMessage.SendData(MessageID.SyncItem, -1, -1, null, i, 0f, 0f, 0f, 0, 0, 0);
                    }
                }
            }
            else
            {
                thisItem.beingGrabbed = false;
            }
            if (thisItem.type == ItemID.PixieDust)
            {
                if (Main.rand.Next(6) == 0)
                {
                    int num33 = Dust.NewDust(thisItem.position, thisItem.width, thisItem.height, 55, 0f, 0f, 200, thisItem.color, 1f);
                    Main.dust[num33].velocity *= 0.3f;
                    Main.dust[num33].scale    *= 0.5f;
                }
            }
            else if (thisItem.type == ItemID.DD2EnergyCrystal)
            {
                Lighting.AddLight(thisItem.Center, 0.1f, 0.3f, 0.1f);
            }
            else if (thisItem.type == ItemID.AmethystGemsparkBlock)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.75f, 0f, 0.75f);
            }
            else if (thisItem.type == ItemID.SapphireGemsparkBlock)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0f, 0f, 0.75f);
            }
            else if (thisItem.type == ItemID.TopazGemsparkBlock)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.75f, 0.75f, 0f);
            }
            else if (thisItem.type == ItemID.EmeraldGemsparkBlock)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0f, 0.75f, 0f);
            }
            else if (thisItem.type == ItemID.RubyGemsparkBlock)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.75f, 0f, 0f);
            }
            else if (thisItem.type == ItemID.DiamondGemsparkBlock)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.75f, 0.75f, 0.75f);
            }
            else if (thisItem.type == ItemID.AmberGemsparkBlock)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.75f, 0.375f, 0f);
            }
            else if (thisItem.type == ItemID.AmethystGemsparkWall)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.6f, 0f, 0.6f);
            }
            else if (thisItem.type == ItemID.SapphireGemsparkWall)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0f, 0f, 0.6f);
            }
            else if (thisItem.type == ItemID.TopazGemsparkWall)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.6f, 0.6f, 0f);
            }
            else if (thisItem.type == ItemID.EmeraldGemsparkWall)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0f, 0.6f, 0f);
            }
            else if (thisItem.type == ItemID.RubyGemsparkWall)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.6f, 0f, 0f);
            }
            else if (thisItem.type == ItemID.DiamondGemsparkWall)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.6f, 0.6f, 0.6f);
            }
            else if (thisItem.type == ItemID.AmberGemsparkWall)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.6f, 0.375f, 0f);
            }
            else if (thisItem.type == ItemID.Torch || thisItem.type == ItemID.Candle)
            {
                if (!thisItem.wet)
                {
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 1f, 0.95f, 0.8f);
                }
            }
            else if (thisItem.type == ItemID.LivingFireBlock)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.7f, 0.65f, 0.55f);
            }
            else if (thisItem.type == ItemID.CursedTorch)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.85f, 1f, 0.7f);
            }
            else if (thisItem.type == ItemID.IceTorch)
            {
                if (!thisItem.wet)
                {
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.7f, 0.85f, 1f);
                }
            }
            else if (thisItem.type == ItemID.IchorTorch)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 1.25f, 1.25f, 0.8f);
            }
            else if (thisItem.type == ItemID.RainbowTorch)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), (float)Main.DiscoR / 255f, (float)Main.DiscoG / 255f, (float)Main.DiscoB / 255f);
            }
            else if (thisItem.type == ItemID.BoneTorch)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.95f, 0.65f, 1.3f);
            }
            else if (thisItem.type == ItemID.UltrabrightTorch)
            {
                float r = 0.75f;
                float g = 1.3499999f;
                float b = 1.5f;
                if (!thisItem.wet)
                {
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), r, g, b);
                }
            }
            else if (thisItem.type >= ItemID.BlueTorch && thisItem.type <= ItemID.YellowTorch)
            {
                if (!thisItem.wet)
                {
                    float r2    = 0f;
                    float g2    = 0f;
                    float b2    = 0f;
                    int   num34 = thisItem.type - 426;
                    if (num34 == 1)
                    {
                        r2 = 0.1f;
                        g2 = 0.2f;
                        b2 = 1.1f;
                    }
                    if (num34 == 2)
                    {
                        r2 = 1f;
                        g2 = 0.1f;
                        b2 = 0.1f;
                    }
                    if (num34 == 3)
                    {
                        r2 = 0f;
                        g2 = 1f;
                        b2 = 0.1f;
                    }
                    if (num34 == 4)
                    {
                        r2 = 0.9f;
                        g2 = 0f;
                        b2 = 0.9f;
                    }
                    if (num34 == 5)
                    {
                        r2 = 1.3f;
                        g2 = 1.3f;
                        b2 = 1.3f;
                    }
                    if (num34 == 6)
                    {
                        r2 = 0.9f;
                        g2 = 0.9f;
                        b2 = 0f;
                    }
                    Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), r2, g2, b2);
                }
            }
            else if (thisItem.type == ItemID.NebulaAxe || thisItem.type == ItemID.NebulaChainsaw || thisItem.type == ItemID.NebulaDrill || thisItem.type == ItemID.NebulaHammer || thisItem.type == ItemID.NebulaPickaxe || thisItem.type == ItemID.NebulaHelmet || thisItem.type == ItemID.NebulaBreastplate || thisItem.type == ItemID.NebulaLeggings || thisItem.type == ItemID.LunarHamaxeNebula)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.4f, 0.16f, 0.36f);
            }
            else if (thisItem.type == ItemID.VortexAxe || thisItem.type == ItemID.VortexChainsaw || thisItem.type == ItemID.VortexDrill || thisItem.type == ItemID.VortexHammer || thisItem.type == ItemID.VortexPickaxe || thisItem.type == ItemID.VortexHelmet || thisItem.type == ItemID.VortexBreastplate || thisItem.type == ItemID.VortexLeggings || thisItem.type == ItemID.LunarHamaxeVortex)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0f, 0.36f, 0.4f);
            }
            else if (thisItem.type == ItemID.SolarFlareAxe || thisItem.type == ItemID.SolarFlareChainsaw || thisItem.type == ItemID.SolarFlareDrill || thisItem.type == ItemID.SolarFlareHammer || thisItem.type == ItemID.SolarFlarePickaxe || thisItem.type == ItemID.SolarFlareHelmet || thisItem.type == ItemID.SolarFlareBreastplate || thisItem.type == ItemID.SolarFlareLeggings || thisItem.type == ItemID.LunarHamaxeSolar)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)(thisItem.width / 2)) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.5f, 0.25f, 0.05f);
            }
            else if (thisItem.type == ItemID.StardustAxe || thisItem.type == ItemID.StardustChainsaw || thisItem.type == ItemID.StardustDrill || thisItem.type == ItemID.StardustHammer || thisItem.type == ItemID.StardustPickaxe || thisItem.type == ItemID.StardustHelmet || thisItem.type == ItemID.StardustBreastplate || thisItem.type == ItemID.StardustLeggings || thisItem.type == ItemID.LunarHamaxeStardust)
            {
                Lighting.AddLight(thisItem.Center, 0.3f, 0.3f, 0.2f);
            }
            else if (thisItem.type == ItemID.FlamingArrow)
            {
                if (!thisItem.wet)
                {
                    Lighting.AddLight((int)((thisItem.position.X + (float)thisItem.width) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 1f, 0.75f, 0.55f);
                }
            }
            else if (thisItem.type == ItemID.FrostburnArrow)
            {
                if (!thisItem.wet)
                {
                    Lighting.AddLight((int)((thisItem.position.X + (float)thisItem.width) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.35f, 0.65f, 1f);
                }
            }
            else if (thisItem.type == ItemID.Glowstick)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)thisItem.width) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.7f, 1f, 0.8f);
            }
            else if (thisItem.type == ItemID.StickyGlowstick)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)thisItem.width) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.7f, 0.8f, 1f);
            }
            else if (thisItem.type == ItemID.BouncyGlowstick)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)thisItem.width) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 1f, 0.6f, 0.85f);
            }
            else if (thisItem.type == ItemID.SpelunkerGlowstick)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)thisItem.width) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 1.05f, 0.95f, 0.55f);
            }
            else if (thisItem.type == ItemID.JungleSpores)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)thisItem.width) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.55f, 0.75f, 0.6f);
            }
            else if (thisItem.type == ItemID.GlowingMushroom)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)thisItem.width) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.15f, 0.45f, 0.9f);
            }
            else if (thisItem.type == ItemID.FallenStar)
            {
                Lighting.AddLight((int)((thisItem.position.X + (float)thisItem.width) / 16f), (int)((thisItem.position.Y + (float)(thisItem.height / 2)) / 16f), 0.8f, 0.7f, 0.1f);
            }
            if (thisItem.type == ItemID.FallenStar)
            {
                if (Main.rand.Next(25) == 0)
                {
                    Dust.NewDust(thisItem.position, thisItem.width, thisItem.height, 58, thisItem.velocity.X * 0.5f, thisItem.velocity.Y * 0.5f, 150, default(Color), 1.2f);
                }
                if (Main.rand.Next(50) == 0)
                {
                    Gore.NewGore(thisItem.position, new Vector2(thisItem.velocity.X * 0.2f, thisItem.velocity.Y * 0.2f), Main.rand.Next(16, 18), 1f);
                }
            }
            if (thisItem.spawnTime < 2147483646)
            {
                if (thisItem.type == ItemID.Heart || thisItem.type == ItemID.Star || thisItem.type == ItemID.CandyCane || thisItem.type == ItemID.SugarPlum || thisItem.type == ItemID.CandyApple || thisItem.type == ItemID.SoulCake)
                {
                    thisItem.spawnTime += 4;
                }
                thisItem.spawnTime++;
            }
            ItemLoader.PostUpdate(thisItem);
            if (Main.netMode == NetmodeID.Server && thisItem.owner != Main.myPlayer)
            {
                thisItem.release++;
                if (thisItem.release >= 300)
                {
                    thisItem.release = 0;
                    NetMessage.SendData(MessageID.ResetItemOwner, thisItem.owner, -1, null, i, 0f, 0f, 0f, 0, 0, 0);
                }
            }
            if (thisItem.wet)
            {
                thisItem.position += vector;
            }
            else
            {
                thisItem.position += thisItem.velocity;
            }
            if (thisItem.noGrabDelay > 0)
            {
                thisItem.noGrabDelay--;
            }
        }
Example #58
0
        public override bool NewRightClick(int i, int j)
        {
            Player player = Main.LocalPlayer;
            Tile   tile   = Main.tile[i, j];

            Main.mouseRightRelease = false;
            int left = i;
            int top  = j;

            if (tile.frameX % 36 != 0)
            {
                left--;
            }
            if (tile.frameY != 0)
            {
                top--;
            }
            if (player.sign >= 0)
            {
                Main.PlaySound(SoundID.MenuClose);
                player.sign      = -1;
                Main.editSign    = false;
                Main.npcChatText = "";
            }
            if (Main.editChest)
            {
                Main.PlaySound(SoundID.MenuTick);
                Main.editChest   = false;
                Main.npcChatText = "";
            }
            if (player.editedChestName)
            {
                NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0);
                player.editedChestName = false;
            }
            bool isLocked = IsLockedChest(left, top);

            if (Main.netMode == NetmodeID.MultiplayerClient && !isLocked)
            {
                if (left == player.chestX && top == player.chestY && player.chest >= 0)
                {
                    player.chest = -1;
                    Recipe.FindRecipes();
                    Main.PlaySound(SoundID.MenuClose);
                }
                else
                {
                    NetMessage.SendData(31, -1, -1, null, left, top, 0f, 0f, 0, 0, 0);
                    Main.stackSplit = 600;
                }
            }
            else
            {
                if (isLocked)
                {
                    int key = ModContent.ItemType <Items.Usable.InfernoKey>();
                    if (player.ConsumeItem(key) && Chest.Unlock(left, top))
                    {
                        if (Main.netMode == NetmodeID.MultiplayerClient)
                        {
                            NetMessage.SendData(MessageID.Unlock, -1, -1, null, player.whoAmI, 1f, left, top);
                        }
                    }
                }
                else
                {
                    int chest = Chest.FindChest(left, top);
                    if (chest >= 0)
                    {
                        Main.stackSplit = 600;
                        if (chest == player.chest)
                        {
                            player.chest = -1;
                            Main.PlaySound(SoundID.MenuClose);
                        }
                        else
                        {
                            player.chest         = chest;
                            Main.playerInventory = true;
                            Main.recBigList      = false;
                            player.chestX        = left;
                            player.chestY        = top;
                            Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick);
                        }
                        Recipe.FindRecipes();
                    }
                }
            }
            return(true);
        }
Example #59
0
 partial void ImplementationSendMessage(NetMessage msg, ReliabilityMode mode);
        public override void AI(Projectile projectile)
        {
            if (projectile.Center.X > 0 && projectile.Center.X / 16 < Main.maxTilesX &&
                projectile.Center.Y > 0 && projectile.Center.Y / 16 < Main.maxTilesY &&
                Framing.GetTileSafely(projectile.Center).type == TileID.PlanteraBulb)
            {
                WorldGen.KillTile((int)projectile.Center.X / 16, (int)projectile.Center.Y / 16);
            }

            switch (projectile.type)
            {
            case ProjectileID.Bee:
            case ProjectileID.GiantBee:
                if (FargowiltasSouls.NPCs.EModeGlobalNPC.AnyBossAlive())
                {
                    projectile.timeLeft = 0;
                    projectile.damage   = 0;
                    if (Main.netMode != 1)
                    {
                        int n = NPC.NewNPC((int)projectile.Center.X, (int)projectile.Center.Y, Main.rand.Next(2) == 0 ? NPCID.Bee : NPCID.BeeSmall);
                        if (n < 200)
                        {
                            Main.npc[n].velocity = projectile.velocity;
                            if (Main.netMode == 2)
                            {
                                NetMessage.SendData(23, -1, -1, null, n);
                            }
                        }
                    }
                }
                break;

            case ProjectileID.EyeFire:
                projectile.position += projectile.velocity / 2;
                break;

            case ProjectileID.MoonLeech:
                if (projectile.Center == Main.player[(int)projectile.ai[1]].Center && Main.player[(int)projectile.ai[1]].active && !Main.player[(int)projectile.ai[1]].dead)
                {
                    Main.player[(int)projectile.ai[1]].position += Main.player[(int)projectile.ai[1]].DirectionTo(Main.npc[(int)projectile.ai[0]].Center) * 5f;
                }
                break;

            case ProjectileID.Sharknado:
            case ProjectileID.Cthulunado:
                if (Main.player[Main.myPlayer].active && !Main.player[Main.myPlayer].dead && projectile.Distance(Main.player[Main.myPlayer].Center) < 1000)
                {
                    Main.player[Main.myPlayer].position += Main.player[Main.myPlayer].DirectionTo(projectile.Center) * 0.1f;
                }
                break;

            case ProjectileID.SandnadoHostile:
                if (Main.player[Main.myPlayer].active && !Main.player[Main.myPlayer].dead && projectile.Distance(Main.player[Main.myPlayer].Center) < 1000)
                {
                    Main.player[Main.myPlayer].position += Main.player[Main.myPlayer].DirectionTo(projectile.Center) * 2;
                }
                break;

            case ProjectileID.FallingStar:
                projectile.hostile = true;
                break;

            case ProjectileID.PhantasmalSphere:
                if (projectile.velocity.Length() == 12f)
                {
                    projectile.Kill();
                    if (Main.netMode != 1)
                    {
                        for (int i = 0; i < 15; i++)
                        {
                            Projectile.NewProjectile(projectile.Center, projectile.velocity.RotatedBy(Math.PI * 2 / 15 * i), mod.ProjectileType("EyePhantom"), projectile.damage, projectile.knockBack, projectile.owner);
                        }
                    }
                }
                if (++counter > 90)
                {
                    counter = 0;
                    int p = Player.FindClosest(projectile.Center, 0, 0);
                    if (p != -1 && Main.netMode != 1)
                    {
                        Projectile.NewProjectile(projectile.Center, projectile.DirectionTo(Main.player[p].Center) * 8, ProjectileID.PhantasmalBolt, 30, 0f, Main.myPlayer);
                    }
                }
                break;

            case ProjectileID.PhantasmalBolt:
                if (projectile.timeLeft > 720)
                {
                    projectile.timeLeft = 720;
                }
                break;

            case ProjectileID.PhantasmalDeathray:
                if (!masobool)
                {
                    masobool = true;
                    if (Main.netMode != 1)
                    {
                        float rotationDirection = (float)Math.PI / 4f / 120f * 3f;     //positive is CW, negative is CCW
                        Projectile.NewProjectile(projectile.Center, projectile.velocity, MasomodeEX.Souls.ProjectileType("PhantasmalDeathrayML"), 4999, 0f, Main.myPlayer, rotationDirection, projectile.ai[1]);
                        Projectile.NewProjectile(projectile.Center, projectile.velocity, MasomodeEX.Souls.ProjectileType("PhantasmalDeathrayML"), 4999, 0f, Main.myPlayer, -rotationDirection, projectile.ai[1]);
                    }
                }
                break;

            default:
                break;
            }
        }