示例#1
0
        /// <summary>
        /// Finds required group by the given object. If it is not exists so the new is created
        /// just with given object.
        /// </summary>
        /// <param name="imgo">The object which the group is looking for.</param>
        /// <returns>Returns the founded group or a new one</returns>
        public GroupMovables GetGroup(IMovableGameObject imgo)
        {
            GroupMovables group;

            if (imgoGroupDict.ContainsKey(imgo))
            {
                group = imgoGroupDict[imgo];
            }
            else
            {
                group = new GroupMovables(imgo.Team);
                group.InsertMemeber(imgo);
                imgoGroupDict.Add(imgo, group);
            }
            return(group);
        }
示例#2
0
        /// <summary>
        /// Inserts given IMovableGameObject to the group. Also recounts old group.
        /// </summary>
        /// <param name="group">The member which will be inserted to this group.</param>
        /// <param name="gameObject">The object which will be inesrted.</param>
        public void AddToGroup(GroupMovables group, IGameObject gameObject)
        {
            var imgo = gameObject as IMovableGameObject;

            if (imgo != null)
            {
                if (imgoGroupDict.ContainsKey(imgo))
                {
                    var removeFromGroup = imgoGroupDict[imgo];
                    removeFromGroup.RemoveMember(imgo);
                    removeFromGroup.CountBasicBonuses();
                    imgoGroupDict[imgo] = group;
                }
                else
                {
                    imgoGroupDict.Add(imgo, group);
                }
                group.InsertMemeber(imgo);
            }
        }
示例#3
0
        /// <summary>
        /// Removes objects from their group and creates new one.
        /// The list can contains some IStaticGameObjects so they must be removed.
        /// New created group is selected (Select - bonuses are counted and are setted).
        /// </summary>
        /// <param name="igoList">The List with IStaticGameObjects and IMovableGameObjects</param>
        /// <returns>Returns created group with IMovableGameObjects from the igoList</returns>
        public GroupMovables CreateSelectedGroupMovable(List <IGameObject> igoList)
        {
            var toRecount = new List <GroupMovables>();
            var group     = new GroupMovables(igoList[0].Team);

            foreach (var igo in igoList)
            {
                var imgo = igo as IMovableGameObject;
                if (imgo != null)
                {
                    group.InsertMemeber(imgo);
                    if (imgoGroupDict.ContainsKey(imgo))
                    {
                        // Add object to toRecount
                        if (!toRecount.Contains(imgoGroupDict[imgo]))
                        {
                            toRecount.Add(imgoGroupDict[imgo]);
                        }
                        // Remove from old group and set new one to Dict
                        imgoGroupDict[imgo].RemoveMember(imgo);
                        imgoGroupDict[imgo] = group;
                    }
                    else
                    {
                        imgoGroupDict.Add(imgo, group);
                    }
                }
            }

            // Recount all modified groups
            foreach (var groupRec in toRecount)
            {
                // Recount just basic bonuses, others are removed when the source of them is removed.
                groupRec.CountBasicBonuses();
            }
            group.Select();
            return(group);
        }
示例#4
0
        /// <summary>
        /// Creates group (without calling Select) from given list with IMovableGameObjects.
        /// Objects from the player team has greater priority then others, so if list contains
        /// any so the others will not be selected.
        /// </summary>
        /// <param Name="isgoList">The List with IMovableGameObjects</param>
        public void CreateInfoGroup(List <IMovableGameObject> imgoList)
        {
            bool inSameGroup = true;

            imgoList = checkPlayersObjects(imgoList);

            // Tests if all imgo are in same selected group
            var firstGroup = GetGroup(imgoList.First());

            for (int i = 1; i < imgoList.Count; i++)
            {
                var memberGroup = GetGroup(imgoList[i]);
                if (firstGroup != memberGroup)
                {
                    // Different groups -> new group must be created (unselected)
                    inSameGroup = false;
                    break;
                }
            }

            if (!inSameGroup)
            {
                // Create new uselect group (selected object was not in same group)
                var group = new GroupMovables(imgoList.First().Team);
                group.InsertMemeber(imgoList[0]);

                if (imgoList.Count > 1)                                 // Check if there is more object
                {
                    for (int i = 1; i < imgoList.Count; i++)
                    {
                        if (imgoList[i].Team.Name == Game.PlayerName && group.Team.Name != Game.PlayerName)
                        {
                            group = new GroupMovables(imgoList[i].Team);
                            group.InsertMemeber(imgoList[i]);                                   // Insert first
                        }
                        else
                        {
                            if (group.Team == imgoList[i].Team)
                            {
                                group.InsertMemeber(imgoList[i]);
                            }
                        }
                    }
                }
                targetedMgr.TargetGroup(group);
            }
            else
            {
                // Objects are in same group. Now must be checked if group is complete.
                if (firstGroup.Count == imgoList.Count)
                {
                    // Absolutly same group just selected the group
                    targetedMgr.TargetGroup(firstGroup);
                }
                else
                {
                    // Subset of group => copy parameters (group is not selected, parameters will only be showed)
                    var group = new GroupMovables(imgoList.First().Team);
                    // Copy bonuses, bonuses will have actual value (changes in the original will be also in this info group)
                    group.GroupBonusDict = firstGroup.GroupBonusDict;

                    foreach (var imgo in imgoList)
                    {
                        group.InsertMemeber(imgo);
                    }
                    targetedMgr.TargetGroup(group);
                }
            }
            targetedMgr.ShowTargetedGroup();
        }