Beispiel #1
0
    public static PlayerDesc AddPlayer(int id, int force, EPlayerType type, string name)
    {
        if (Pathea.PeGameMgr.IsMultiCoop)
        {
            force = 1;
        }

        int index = Instance.GetPlayerIndex(id);

        if (-1 == index)
        {
            PlayerDesc desc = new PlayerDesc();
            desc.ID    = id;
            desc.Force = force;
            desc.Type  = type;
            desc.Name  = name;
            Instance.AddPlayerDesc(desc);
            return(desc);
        }
        else
        {
            Instance.m_Players[index].Force = force;
            return(Instance.m_Players[index]);
        }
    }
Beispiel #2
0
    public void AddPlayerDesc(PlayerDesc desc)
    {
        if (desc != null)
        {
            int index = GetPlayerIndex(desc.ID);
            if (index == -1)
            {
                m_Players.Add(desc);
            }
            else
            {
                m_Players[index] = desc;
                if (LogFilter.logDebug)
                {
                    Debug.LogWarningFormat("replace player id:{0}", desc.ID);
                }
            }

            if (Pathea.PeGameMgr.IsMulti)
            {
                ReputationSystem.Instance.AddForceID(desc.Force);
            }
        }
    }
Beispiel #3
0
        public static bool PlayerCheck(int curr_player_id, int query_player, OBJECT player)
        {
            if (player.type != OBJECT.OBJECTTYPE.Player)
            {
                return(false);
            }

            // 判断 player id
            if (player.isAnyPlayer)
            {
                return(true);
            }
            if (player.isPlayerId)
            {
                return(player.Id == query_player);
            }
            if (player.isCurrentPlayer)
            {
                return(curr_player_id == query_player);
            }
            if (player.isAnyOtherPlayer)
            {
                return(curr_player_id != query_player);
            }

            // 根据 player_id 在 ForceSettings 里面获取 player_force
            int curr_player_force  = CustomGameData.Mgr.Instance.curGameData.curPlayer.Force;
            int query_player_force = 0;

            PlayerDesc pd = CustomGameData.Mgr.Instance.curGameData.mPlayerDescs.Find(iter => iter.ID == query_player);

            if (pd != null)
            {
                query_player_force = pd.Force;
            }

            if (player.isForceId)
            {
                return(query_player_force == player.Group);
            }
            if (player.isAnyOtherForce)
            {
                return(curr_player_force != query_player_force);
            }

            // 对 Ally force 和 Enemy force 进行判断
            ForceDesc fd = CustomGameData.Mgr.Instance.curGameData.mForceDescs.Find(iter => iter.ID == curr_player_force);

            if (fd != null)
            {
                if (player.isAllyForce)
                {
                    return(fd.Allies.Contains(query_player_force));
                }
                else if (player.isEnemyForce)
                {
                    return(!fd.Allies.Contains(query_player_force));
                }
            }

            return(false);
        }
Beispiel #4
0
        public void SwapItem(SlotData slot1, SlotData slot2)
        {
            Entity en1 = Parent.GetEntity(slot1.ObjectId);
            Entity en2 = Parent.GetEntity(slot2.ObjectId);

            (en1 as IContainer)?.UpdateInventorySlot(slot1.SlotId);
            (en2 as IContainer)?.UpdateInventorySlot(slot2.SlotId);

            //Undefined entities
            if (en1 == null || en2 == null)
            {
#if DEBUG
                Program.Print(PrintType.Error, "Undefined entities");
#endif
                Client.Send(InvalidInvSwap);
                return;
            }

            //Entities which are not containers???
            if (!(en1 is IContainer) || !(en2 is IContainer))
            {
#if DEBUG
                Program.Print(PrintType.Error, "Not containers");
#endif
                Client.Send(InvalidInvSwap);
                return;
            }

            if (en1.Position.Distance(en2) > ContainerMinimumDistance)
            {
#if DEBUG
                Program.Print(PrintType.Error, "Too far away from container");
#endif
                Client.Send(InvalidInvSwap);
                return;
            }

            //Player manipulation attempt
            if ((en1 is Player && slot1.ObjectId != Id) ||
                (en2 is Player && slot2.ObjectId != Id))
            {
#if DEBUG
                Program.Print(PrintType.Error, "Player manipulation attempt");
#endif
                Client.Send(InvalidInvSwap);
                return;
            }

            //Container manipulation attempt
            if ((en1 is Container &&
                 (en1 as Container).OwnerId != -1 &&
                 Id != (en1 as Container).OwnerId) ||
                (en2 is Container &&
                 (en2 as Container).OwnerId != -1 &&
                 Id != (en2 as Container).OwnerId))
            {
#if DEBUG
                Program.Print(PrintType.Error, "Container manipulation attempt");
#endif
                Client.Send(InvalidInvSwap);
                return;
            }

            IContainer con1 = en1 as IContainer;
            IContainer con2 = en2 as IContainer;

            //Invalid slots
            if (!con1.ValidSlot(slot1.SlotId) || !con2.ValidSlot(slot2.SlotId))
            {
#if DEBUG
                Program.Print(PrintType.Error, "Invalid inv swap");
#endif
                Client.Send(InvalidInvSwap);
                return;
            }

            //Invalid slot types
            int        item1 = con1.Inventory[slot1.SlotId];
            int        data1 = con1.ItemDatas[slot1.SlotId];
            int        item2 = con2.Inventory[slot2.SlotId];
            int        data2 = con2.ItemDatas[slot2.SlotId];
            PlayerDesc d     = Desc as PlayerDesc;
            ItemDesc   d1;
            ItemDesc   d2;
            Resources.Type2Item.TryGetValue((ushort)item1, out d1);
            Resources.Type2Item.TryGetValue((ushort)item2, out d2);

            if (con1 is Player)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (slot1.SlotId == i)
                    {
                        if ((d1 != null && d.SlotTypes[i] != d1.SlotType) ||
                            (d2 != null && d.SlotTypes[i] != d2.SlotType))
                        {
#if DEBUG
                            Program.Print(PrintType.Error, "Invalid slot type");
#endif
                            Client.Send(InvalidInvSwap);
                            return;
                        }
                    }
                }
            }

            if (con2 is Player)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (slot2.SlotId == i)
                    {
                        if ((d1 != null && d.SlotTypes[i] != d1.SlotType) ||
                            (d2 != null && d.SlotTypes[i] != d2.SlotType))
                        {
#if DEBUG
                            Program.Print(PrintType.Error, "Invalid slot type");
#endif
                            Client.Send(InvalidInvSwap);
                            return;
                        }
                    }
                }
            }

            con1.Inventory[slot1.SlotId] = item2;
            con1.ItemDatas[slot1.SlotId] = data2;
            con2.Inventory[slot2.SlotId] = item1;
            con2.ItemDatas[slot2.SlotId] = data1;
            con1.UpdateInventorySlot(slot1.SlotId);
            con2.UpdateInventorySlot(slot2.SlotId);
            RecalculateEquipBonuses();
            Client.Send(ValidInvSwap);
        }
 public void ResetAll()
 {
     this.RoleNameLabel.text = "";
     this.m_RoleInfo         = null;
     this.ResetPlayer();
 }
 public void SetFixRole(PlayerDesc roleInfo)
 {
     this.ResetAll();
     this.m_RoleInfo = roleInfo;
     this.UpdateRoleName(this.m_RoleInfo == null?"":this.m_RoleInfo.Name);
 }
Beispiel #7
0
    public void Load(string s)
    {
        //if(Pathea.PeGameMgr.IsSingle)
        {
            m_Forces.Clear();
            m_Players.Clear();
        }

        XmlDocument  doc    = new XmlDocument();
        StringReader reader = new StringReader(s);

        doc.Load(reader);

        XmlNode root = doc.SelectSingleNode("ForceSetting");

        //add force
        XmlNode     forceNode = root.SelectSingleNode("Force");
        XmlNodeList forceList = ((XmlElement)forceNode).GetElementsByTagName("ForceDesc");

        foreach (XmlNode node in forceList)
        {
            XmlElement xe = node as XmlElement;

            ForceDesc force = new ForceDesc();
            force.ID     = XmlUtil.GetAttributeInt32(xe, "ID");
            force.Name   = XmlUtil.GetAttributeString(xe, "Name");
            force.Color  = XmlUtil.GetNodeColor32(xe, "Color");
            force.Allies = XmlUtil.GetNodeInt32List(xe, "Ally");
            force.JoinablePlayerCount = XmlUtil.GetNodeInt32(xe, "JoinablePlayerCount");
            force.JoinStr             = XmlUtil.GetNodeString(xe, "JoinLocation");
            force.ItemUseShare        = XmlUtil.GetNodeBool(xe, "ItemUseShare");
            force.ItemShare           = XmlUtil.GetNodeBool(xe, "ItemShare");
            force.InternalConflict    = XmlUtil.GetNodeBool(xe, "InternalConflict");
            force.AllyConflict        = XmlUtil.GetNodeBool(xe, "AllyConflict");
            force.EnemyConflict       = XmlUtil.GetNodeBool(xe, "EnemyConflict");

            force.Color.a = 255;

            AddForceDesc(force);
        }

        //add player
        XmlNode     playerNode = root.SelectSingleNode("Player");
        XmlNodeList playerList = ((XmlElement)playerNode).GetElementsByTagName("PlayerDesc");

        foreach (XmlNode node in playerList)
        {
            XmlElement xe = node as XmlElement;

            PlayerDesc player = new PlayerDesc();
            player.ID       = XmlUtil.GetAttributeInt32(xe, "ID");
            player.Name     = XmlUtil.GetAttributeString(xe, "Name");
            player.Force    = XmlUtil.GetAttributeInt32(xe, "Force");
            player.StartStr = XmlUtil.GetAttributeString(xe, "Start");

            player.Type = (EPlayerType)System.Enum.Parse(typeof(EPlayerType), XmlUtil.GetAttributeString(xe, "Type"));

            AddPlayerDesc(player);
        }

        reader.Close();
    }