Esempio n. 1
0
        public void SendAddMessage(ThrownOutItem item)
        {
            List <string> adData   = new List <string>();
            Item          itemDesc = ItemStorage.GetItemDesc(item.ItemServerId);

            adData.Add("addThrownItem");
            adData.Add(itemDesc.ItemStaticId.ToString());
            adData.Add(itemDesc.ServerId.ToString());
            adData.Add(ForgetiveServer.Base64Encode(itemDesc.DescribeMessage));
            adData.Add(ForgetiveServer.Base64Encode(itemDesc.ExtraInfo));
            adData.Add(item.Location.ToXYZ());
            for (int i = 0; i < Map.players.Count; i++)
            {
                try
                {
                    Map.players[i].SendDataPackage(adData);
                }
                catch { }
            }
        }
Esempio n. 2
0
        public void SendToNewPlayer(Player player)
        {
            List <string> data = new List <string>();

            data.Add("updateThrownItems");
            for (int i = 0; i < Items.Count; i++)
            {
                int  index    = Items[i].ItemServerId;
                Item itemdesc = ItemStorage.GetItemDesc(index);
                if (itemdesc == null)
                {
                    continue;
                }
                data.Add(itemdesc.ItemStaticId.ToString());
                data.Add(itemdesc.ServerId.ToString());
                data.Add(ForgetiveServer.Base64Encode(itemdesc.DescribeMessage));
                data.Add(ForgetiveServer.Base64Encode(itemdesc.ExtraInfo));
                data.Add(Items[i].Location.ToXYZ());
                data.Add("next");
                player.SendDataPackage(data);
            }
        }
Esempio n. 3
0
        internal void WRecv(Player selectPlayer, string[] msgs)
        {
            List <string> data = new List <string>();

            switch (msgs[0])
            {
            case "damageSelf":
                if (selectPlayer.IsDead)
                {
                    return;
                }
                if (!CheckPam(msgs, 3, 2))
                {
                    return;
                }

                if (IsInSafeArea(selectPlayer.Location, true))
                {
                    break;
                }

                selectPlayer.LastDamageSourceStr = msgs[1];
                selectPlayer.Health -= float.Parse(msgs[2]);

                if (selectPlayer.Health > 0)
                {
                    selectPlayer.IsInAttackAnimation = true;
                    selectPlayer.animDelay.SetDelay(500, () => selectPlayer.IsInAttackAnimation = false);
                }

                data.Add("damage");
                data.Add(msgs[1]);
                data.Add(selectPlayer.Health.ToString());

                selectPlayer.SendDataPackage(data);
                break;

            case "damageOther":
                string killerName = selectPlayer.Name;
                Player killer     = selectPlayer;

                if (selectPlayer.IsDead)
                {
                    return;
                }
                if (!CheckPam(msgs, 4, 2))
                {
                    return;
                }

                if (IsInSafeArea(selectPlayer.Location, false))
                {
                    break;
                }

                string attackObj = msgs[3];
                if (msgs[3].Contains("onlineplayer_"))
                {
                    attackObj = msgs[3].Substring(13);
                }

                selectPlayer = FindPlayer(attackObj);
                if (selectPlayer == null)
                {
                    return;
                }

                if (IsInSafeArea(selectPlayer.Location, false))
                {
                    break;
                }
                if (selectPlayer.IsDead)
                {
                    break;
                }

                selectPlayer.LastDamageSourceStr = msgs[1];
                selectPlayer.Health -= float.Parse(msgs[2]);

                if (selectPlayer.Health <= 0)
                {
                    if (selectPlayer.XCoin >= 500)
                    {
                        int xcoin = selectPlayer.XCoin / 40;
                        if (xcoin > 1000)
                        {
                            xcoin = 1000;
                        }
                        selectPlayer.XCoin -= xcoin;
                        selectPlayer.SendChat("你失去了" + xcoin + "X币", "Forgetive");
                        killer.XCoin += xcoin;
                        killer.SendChat("你得到了" + xcoin + "X币", "Forgetive");
                        SendAllChat(killerName + " 击杀了 " + selectPlayer.Name + " 并抢夺了财产 " + xcoin + "X币", "Forgetive");
                    }
                    else
                    {
                        SendAllChat(killerName + " 击杀了 " + selectPlayer.Name, "Forgetive");
                    }
                }
                else
                {
                    selectPlayer.IsInAttackAnimation = true;
                    selectPlayer.animDelay.SetDelay(500, () => selectPlayer.IsInAttackAnimation = false);
                }

                data.Add("damage");
                data.Add(msgs[1]);
                data.Add(selectPlayer.Health.ToString());

                selectPlayer.SendDataPackage(data);
                break;

            case "updateSelf":
            {
                if (selectPlayer.IsDead)
                {
                    return;
                }
                if (selectPlayer.LastLocation == Vector3.Zero)
                {
                    selectPlayer.LastLocation = new Vector3(-1f, -1f, -1f);
                }
                else
                {
                    selectPlayer.LastLocation = selectPlayer.Location;
                }
                selectPlayer.Location = new Vector3(msgs[1]);
                selectPlayer.Rotation = new Vector3(msgs[2]);
                int.TryParse(msgs[3], out selectPlayer.State);
                selectPlayer.CalcLocationChanged();
            }
            break;

            case "getUserItems":
                data.Add("updateFullItems");
                for (int i = 0; i < selectPlayer.Items.Count; i++)
                {
                    int  index    = selectPlayer.Items[i];
                    Item itemdesc = ItemStorage.GetItemDesc(index);
                    if (itemdesc == null)
                    {
                        continue;
                    }
                    data.Add(itemdesc.ItemStaticId.ToString());
                    data.Add(itemdesc.ServerId.ToString());
                    data.Add(Base64Encode(itemdesc.DescribeMessage));
                    data.Add(Base64Encode(itemdesc.ExtraInfo));
                    data.Add("next");
                }
                selectPlayer.SendDataPackage(data);
                data = new List <string>();
                data.Add("updateDockItems");
                for (int i = 0; i < selectPlayer.BarItemsId.Count; i++)
                {
                    data.Add(selectPlayer.BarItemsId[i].ToString());
                }
                selectPlayer.SendDataPackage(data);

                break;

            case "setUserDocks":
                if (selectPlayer.IsDead)
                {
                    return;
                }
                List <int> dockIds = new List <int>();
                for (int i = 0; i < msgs.Length; i++)
                {
                    if (i == 0)
                    {
                        continue;
                    }
                    int id = int.Parse(msgs[i]);
                    dockIds.Add(id);
                }
                selectPlayer.BarItemsId = dockIds;
                break;

            case "useItem":
            {
                if (selectPlayer.IsDead)
                {
                    return;
                }
                int    itemStaticId = int.Parse(msgs[1]);
                int    serverId     = int.Parse(msgs[2]);
                string desc         = Base64Decode(msgs[3]);
                string extra        = Base64Decode(msgs[4]);
                for (int i = 0; i < selectPlayer.Items.Count; i++)
                {
                    if (selectPlayer.Items[i] == serverId)
                    {
                        ItemStorage.SetChanged(serverId, itemStaticId, desc, extra);
                    }
                }
            }
            break;

            case "tryControlBlock":
            {
                if (selectPlayer.IsDead)
                {
                    return;
                }
                string blockName = msgs[1];
                Player srcPlayer = null;
                bool   findBlock = false;
                for (int i = 0; i < blocks.Count; i++)
                {
                    if (blocks[i].blockId == blockName)
                    {
                        srcPlayer = FindPlayer(blocks[i].controllerName);
                        blocks[i].controllerName = selectPlayer.Name;
                        findBlock = true;
                        break;
                    }
                }
                if (!findBlock)
                {
                    Block block = new Block();
                    block.blockId        = blockName;
                    block.controllerName = selectPlayer.Name;
                    blocks.Add(block);
                }
                if (srcPlayer != null)
                {
                    if (selectPlayer.Name == srcPlayer.Name)
                    {
                        return;
                    }
                }
                data.Add("updateBlockController");
                data.Add(blockName);
                data.Add(bool.TrueString);
                selectPlayer.SendDataPackage(data);
                Logger.WriteLine(selectPlayer.Name + "已获得对" + blockName + "的控制权");
                if (srcPlayer == null)
                {
                    return;
                }
                data = new List <string>();
                data.Add("updateBlockController");
                data.Add(blockName);
                data.Add(bool.FalseString);
                srcPlayer.SendDataPackage(data);
                Logger.WriteLine(selectPlayer.Name + "已失去对" + blockName + "的控制权");
            }
            break;

            case "sendBlockState":
            {
                if (selectPlayer.IsDead)
                {
                    return;
                }
                Block   selectBlock = null;
                string  id          = msgs[1];
                Vector3 lctn        = new Vector3(msgs[2]);
                Vector3 rotn        = new Vector3(msgs[3]);
                for (int i = 0; i < blocks.Count; i++)
                {
                    if (blocks[i].blockId == id)
                    {
                        selectBlock = blocks[i];
                        break;
                    }
                }
                if (selectBlock == null)
                {
                    return;
                }
                if (selectBlock.controllerName != selectPlayer.Name)
                {
                    return;
                }
                selectBlock.updateLocation = lctn;
                selectBlock.updateRotation = rotn;

                data.Add("updateBlock");
                data.Add(id);
                data.Add(lctn.ToXYZ());
                data.Add(rotn.ToXYZ());
                data.Add(selectBlock.blockType.ToString());

                SendAll(data);

                //for (int i = 0; i < players.Count; i++)
                //{
                //    Player user = players[i];
                //    if (user != null)
                //    {
                //        if (user.SocketState != null)
                //        {
                //            if (user.SocketState.OtherData != null)
                //            {
                //                user.SocketState.OtherData.Add(new List_String(data));
                //            }
                //        }
                //    }
                //}
            }
            break;

            case "getBlocks":
                for (int i = 0; i < blocks.Count; i++)
                {
                    data = new List <string>();
                    data.Add("updateBlock");
                    data.Add(blocks[i].blockId);
                    data.Add(blocks[i].updateLocation.ToXYZ());
                    data.Add(blocks[i].updateRotation.ToXYZ());
                    data.Add(blocks[i].blockType.ToString());
                    selectPlayer.SendDataPackage(data);
                }
                break;

            case "getSelf":
                data.Add("updateSelfLocation");
                data.Add(selectPlayer.Location.ToXYZ());
                data.Add(selectPlayer.Rotation.ToCameraRotation().ToXYZ());
                selectPlayer.SendDataPackage(data);
                break;

            case "inited":
                selectPlayer.HasRecvInited = true;
                Logger.WriteLine(selectPlayer.Name + "已经完成初始化");
                selectPlayer.OnInited();
                break;

            case "throwItem":
                if (selectPlayer.IsDead)
                {
                    return;
                }
                thrownOutItems.ThrowFromPlayer(int.Parse(msgs[1]), new Vector3(msgs[2]), selectPlayer);
                break;

            case "pickupItem":
                if (selectPlayer.IsDead)
                {
                    return;
                }
                thrownOutItems.PickUpFromPlayer(selectPlayer, int.Parse(msgs[1]));
                break;

            case "updateThrownItems":
                thrownOutItems.SendToNewPlayer(selectPlayer);
                break;

            case "getHealth":
                data.Add("updateSelfHealth");
                data.Add(selectPlayer.Health.ToString());
                selectPlayer.SendDataPackage(data);
                break;

            case "respawn":
                if (selectPlayer.IsDead)
                {
                    selectPlayer.Health = RespawnOnDeadHealth;
                    data.Add("respawnCallback");
                    data.Add(true.ToString());
                    data.Add(RespawnOnDeadHealth.ToString());
                    data.Add(RespawnPoint.ToXYZ());
                    data.Add(RespawnEuler.ToXYZ());
                    selectPlayer.SendDataPackage(data);
                    List <string> dataToAll = new List <string>();
                    dataToAll.Add("playerRespawn");
                    dataToAll.Add(selectPlayer.Name);
                    SendAll(dataToAll);
                }
                else
                {
                    data.Add("respawnCallback");
                    data.Add(true.ToString());
                    data.Add(RespawnOnDeadHealth.ToString());
                    data.Add(RespawnPoint.ToXYZ());
                    data.Add(RespawnEuler.ToXYZ());
                    selectPlayer.SendDataPackage(data);
                }
                break;

            case "useItemEx":
                if (selectPlayer.IsDead)
                {
                    return;
                }
                ItemUsage.Invoke(int.Parse(msgs[1]), selectPlayer);
                break;

            case "startBomb":
                if (selectPlayer.MapContext == null)
                {
                    return;
                }
                selectPlayer.MapContext.ThrowItems.RecvBombData(int.Parse(msgs[1]), new Vector3(msgs[2]));
                break;

            case "changeThrownItemLctn":
                thrownOutItems.ChangeItemLocation(int.Parse(msgs[1]), new Vector3(msgs[2]));
                break;

            case "removeBlock":
            {
                for (int i = 0; i < blocks.Count; i++)
                {
                    if (blocks[i].blockId == msgs[1])
                    {
                        data.Add("removeBlock");
                        data.Add(blocks[i].blockId);
                        blocks.RemoveAt(i);
                        SendAll(data);
                    }
                }
            }
            break;

            case "buyItem":
            {
                int    staticId     = int.Parse(msgs[1]);
                string desc         = Base64Decode(msgs[2]);
                string extra        = Base64Decode(msgs[3]);
                int    cost         = int.Parse(msgs[4]);
                bool   isPayInXCoin = bool.Parse(msgs[5]);
                int    idc          = selectPlayer.BuyItem(staticId, desc, extra, cost, isPayInXCoin);
                data.Add("buyItemCallback");
                data.Add(idc.ToString());
                selectPlayer.ReplaceData(data);
                selectPlayer.SendXCoinAndBPData();
            }
            break;

            case "morebp":
            {
                int xcoin = int.Parse(msgs[1]);
                int bp    = int.Parse(msgs[2]);
                int idc   = selectPlayer.XCoinToBP(xcoin, bp);
                data.Add("morebpCallback");
                data.Add(idc.ToString());
                selectPlayer.ReplaceData(data);
                selectPlayer.SendXCoinAndBPData();
            }
            break;

            case "updateNewPlayerHelpStep":
            {
                int m = int.Parse(msgs[1]);
                if (selectPlayer.NewPlayerStep != -1)
                {
                    if (m == -1)
                    {
                        selectPlayer.BP += 1000;
                        selectPlayer.SendChat("你完成了新手引导任务,获得1000金币", "Forgetive");
                    }
                }
                selectPlayer.NewPlayerStep = m;
            }
            break;

            case "updateNPCState":
            {
                for (int i = 1; i < msgs.Length; i++)
                {
                    NPCManager.RecvDataFromHost(new NPCHostToServerData(msgs[i]), selectPlayer);
                }
            }
            break;

            case "damageNPC":
            {
                NPCManager.Attack(int.Parse(msgs[1]), float.Parse(msgs[2]), selectPlayer);
            }
            break;

            default:
                ExecutionContent.clicmd.Call(selectPlayer, msgs);
                break;
            }
            data.Clear();
        }