コード例 #1
0
        private void ServerCharacterGainedLearningPointsHandler(
            ICharacter character,
            int gainedLearningPoints,
            bool isModifiedByStat)
        {
            if (!isModifiedByStat)
            {
                // gained through the quest, by a consumable item, etc
                return;
            }

            var faction = FactionSystem.ServerGetFaction(character);

            if (faction is null)
            {
                return;
            }

            var factionPrivateState = Faction.GetPrivateState(faction);

            factionPrivateState.ServerMetricLearningPoints
                = (uint)Math.Min(factionPrivateState.ServerMetricLearningPoints + gainedLearningPoints,
                                 uint.MaxValue);

            /*Logger.Dev("Learning points metric updated: "
             + gainedLearningPoints.ToString("0.###")
             + " total metric: "
             + factionPrivateState.ServerMetricLearningPoints.ToString("0.###"));*/
        }
コード例 #2
0
        private static void ServerCharacterDeathMechanicOnCharacterKilled(
            ICharacter attackerCharacter,
            ICharacter targetCharacter)
        {
            if (attackerCharacter.IsNpc ||
                !targetCharacter.IsNpc)
            {
                return;
            }

            var faction = FactionSystem.ServerGetFaction(attackerCharacter);

            if (faction is null)
            {
                return;
            }

            // a mob is killed by player
            var rawXP = SkillHunting.ExperienceForKill;

            rawXP *= ((IProtoCharacterMob)targetCharacter.ProtoGameObject).MobKillExperienceMultiplier;
            if (rawXP <= 0)
            {
                return;
            }

            rawXP *= 0.01; // 0.01 is our default XP->LP conversion coefficient (see TechConstants)

            Faction.GetPrivateState(faction).ServerMetricHuntingScore += rawXP;

            /*Logger.Dev("Mob killing metric updated: "
             + rawXP.ToString("0.###")
             + " total metric: "
             + Faction.GetPrivateState(faction).ServerMetricHuntingScore.ToString("0.###"));*/
        }
コード例 #3
0
        public string Execute([CurrentCharacterIfNull] ICharacter player, FactionMemberRole role)
        {
            var faction = FactionSystem.ServerGetFaction(player);

            if (faction is null)
            {
                return($"Player {player.Name} has no faction");
            }

            if (!Api.IsEditor)
            {
                var currentRole = FactionSystem.ServerGetRole(player);
                if (currentRole == FactionMemberRole.Leader)
                {
                    return("Cannot change the role of the faction leader");
                }

                if (role == FactionMemberRole.Leader)
                {
                    return("Cannot assign a leader role to anyone");
                }
            }

            FactionSystem.ServerSetMemberRoleNoChecks(player.Name, faction, role);
            return("Role changed to " + role);
        }
コード例 #4
0
        public string Execute(ICharacter player)
        {
            var faction = FactionSystem.ServerGetFaction(player);

            if (faction is null)
            {
                return($"Player \"{player.Name}\" has no faction");
            }

            var memberEntries = FactionSystem.ServerGetFactionMembersReadOnly(faction);
            var sb            = new StringBuilder("Player \"")
                                .Append(player.Name)
                                .AppendLine("\" - faction info:")
                                .Append("Clan tag: ")
                                .Append("[")
                                .Append(FactionSystem.SharedGetClanTag(faction))
                                .AppendLine("]")
                                .AppendLine("Members list (with roles): ");

            foreach (var entry in memberEntries)
            {
                sb.Append(" * ").AppendLine(entry.Name + " - " + entry.Role);
            }

            return(sb.ToString());
        }
コード例 #5
0
        private void ServerRemote_TransferToFactionOwnership(IDynamicWorldObject vehicle)
        {
            var character = ServerRemoteContext.Character;

            if (vehicle.ProtoGameObject is not IProtoVehicle)
            {
                throw new Exception("Not a vehicle");
            }

            if (!vehicle.ProtoWorldObject.SharedCanInteract(character,
                                                            vehicle,
                                                            writeToLog: true))
            {
                return;
            }

            var publicState = vehicle.GetPublicState <VehiclePublicState>();

            if (!string.IsNullOrEmpty(publicState.ClanTag))
            {
                Logger.Warning("Already in faction ownership: " + vehicle, character);
                return;
            }

            var faction = FactionSystem.ServerGetFaction(character);

            if (faction is null)
            {
                throw new Exception("Player has no faction");
            }

            /*if (FactionSystem.SharedGetFactionKind(faction)
             *  == FactionKind.Public)
             * {
             *  throw new Exception("Cannot transfer a vehicle to ownership of a public faction");
             * }*/

            var clanTag = FactionSystem.SharedGetClanTag(faction);

            publicState.ClanTag = clanTag;

            var privateState = vehicle.GetPrivateState <VehiclePrivateState>();

            //privateState.Owners.Clear(); // keep the original owners list in case the faction is dissolved
            privateState.FactionAccessMode = WorldObjectFactionAccessModes.Leader
                                             | WorldObjectFactionAccessModes.Officer1
                                             | WorldObjectFactionAccessModes.Officer2
                                             | WorldObjectFactionAccessModes.Officer3;
            Logger.Important($"Vehicle transferred to faction ownership: {vehicle} - [{clanTag}]", character);

            WorldObjectOwnersSystem.ServerOnOwnersChanged(vehicle);
        }
コード例 #6
0
        private static void ServerRaidBlockStartedOrExtendedHandler(
            ILogicObject area,
            ICharacter raiderCharacter,
            bool isNewRaidBlock,
            bool isStructureDestroyed)
        {
            if (!isNewRaidBlock)
            {
                return;
            }

            var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(area);

            if (ServerNotifiedCharactersForAreasGroups.ContainsKey(
                    ServerAllyBaseUnderRaidMark.CreateKeyOnly(areasGroup)))
            {
                // notification for this areas group is already sent
                return;
            }

            ILogicObject faction;
            var          clanTag = LandClaimSystem.SharedGetAreaOwnerFactionClanTag(area);

            if (!string.IsNullOrEmpty(clanTag))
            {
                // owned by a faction, notify allies
                faction = FactionSystem.ServerGetFactionByClanTag(clanTag);
                ServerNotifyFactionAllies(faction, area, areasGroup);
                return;
            }

            // not owned by faction,
            // check whether its founder is a member of any faction and notify its members
            var founderName = LandClaimArea.GetPrivateState(area)
                              .LandClaimFounder;
            var founderCharacter = Server.Characters.GetPlayerCharacter(founderName);

            if (founderCharacter is null)
            {
                return;
            }

            faction = FactionSystem.ServerGetFaction(founderCharacter);
            if (faction is not null)
            {
                ServerNotifyFactionMembers(faction, founderCharacter, area, areasGroup);
            }
        }
コード例 #7
0
        public static ILogicObject ServerGetLandOwnerFactionOrFounderFaction(ILogicObject area)
        {
            ILogicObject faction = null;

            {
                var clanTag = SharedGetAreaOwnerFactionClanTag(area);
                if (!string.IsNullOrEmpty(clanTag))
                {
                    faction = FactionSystem.ServerGetFactionByClanTag(clanTag);
                }
                else
                {
                    var founderName = LandClaimArea.GetPrivateState(area)
                                      .LandClaimFounder;
                    var founderCharacter = Server.Characters.GetPlayerCharacter(founderName);
                    if (founderCharacter is not null)
                    {
                        faction = FactionSystem.ServerGetFaction(founderCharacter);
                    }
                }
            }
            return(faction);
        }
コード例 #8
0
        private void ServerSendOnlineListAndOtherInfo(ICharacter playerCharacter)
        {
            if (!playerCharacter.ServerIsOnline)
            {
                return;
            }

            var isOperatorOrModerator = ServerIsOperatorOrModerator(playerCharacter);
            var isListHidden          = SharedIsListHidden &&
                                        !isOperatorOrModerator;

            var onlinePlayersList = new List <Entry>();

            if (isListHidden)
            {
                // send only the party and faction members
                var faction = FactionSystem.ServerGetFaction(playerCharacter);
                if (faction is not null)
                //&& FactionSystem.SharedGetFactionKind(faction) != FactionKind.Public)
                {
                    var factionClanTag = FactionSystem.SharedGetClanTag(faction);
                    onlinePlayersList.AddRange(
                        Server.Characters
                        .EnumerateAllPlayerCharacters(onlyOnline: true)
                        .ExceptOne(playerCharacter)
                        .Where(c => factionClanTag == FactionSystem.SharedGetClanTag(c))
                        .Select(c => new Entry(c.Name, factionClanTag)));
                }

                var party = PartySystem.ServerGetParty(playerCharacter);
                if (party is not null)
                {
                    var partyMembers = Server.Characters
                                       .EnumerateAllPlayerCharacters(onlyOnline: true)
                                       .ExceptOne(playerCharacter)
                                       .Where(c => party == PartySystem.ServerGetParty(c))
                                       .Select(c => new Entry(c.Name, FactionSystem.SharedGetClanTag(c)));
                    if (onlinePlayersList.Count == 0)
                    {
                        onlinePlayersList.AddRange(partyMembers);
                    }
                    else
                    {
                        foreach (var entry in partyMembers)
                        {
                            onlinePlayersList.AddIfNotContains(entry);
                        }
                    }
                }
            }
            else
            {
                onlinePlayersList = Server.Characters
                                    .EnumerateAllPlayerCharacters(onlyOnline: true)
                                    .ExceptOne(playerCharacter)
                                    .Select(c => new Entry(c.Name,
                                                           FactionSystem.SharedGetClanTag(c)))
                                    .ToList();
            }

            // uncomment to test the online players list with some fake data
            //onlineList.Add(new Entry("Aaa1", "XXX"));
            //onlineList.Add(new Entry("Ссс1", "XXX"));
            //onlineList.Add(new Entry("Bbb1", "XXX"));
            //onlineList.Add(new Entry("Aaa", ""));
            //onlineList.Add(new Entry("Ссс", null));
            //onlineList.Add(new Entry("Bbb", ""));
            //onlineList.Add(new Entry("Aaa2", "YYY"));
            //onlineList.Add(new Entry("Ссс2", "YYY"));
            //onlineList.Add(new Entry("Bbb2", "YYY"));

            this.CallClient(playerCharacter,
                            _ => _.ClientRemote_OnlinePlayersList(onlinePlayersList,
                                                                  isListHidden
                                                                      ? Server.Characters.OnlinePlayersCount
                                                                      : 0));

            // provide info about the total players count only to a server operator or moderator
            var totalPlayersCount = isOperatorOrModerator
                                        ? serverLastTotalPlayersCount
                                        : 0;

            this.CallClient(playerCharacter,
                            _ => _.ClientRemote_TotalPlayerCharactersCountChanged(totalPlayersCount));
        }
コード例 #9
0
        private static List <ICharacter> ServerGetOnlineStatusChangeReceivers(ICharacter aboutPlayerCharacter)
        {
            var list = Server.Characters
                       .EnumerateAllPlayerCharacters(onlyOnline: true)
                       .ToList();

            for (var index = 0; index < list.Count; index++)
            {
                var character = list[index];
                if (ReferenceEquals(character, aboutPlayerCharacter))
                {
                    list.RemoveAt(index);
                    break;
                }
            }

            var    aboutPlayerCharacterParty          = PartySystem.ServerGetParty(aboutPlayerCharacter);
            string aboutPlayerCharacterFactionClanTag = null;
            {
                var faction = FactionSystem.ServerGetFaction(aboutPlayerCharacter);
                if (faction is not null)
                {
                    /*if (FactionSystem.SharedGetFactionKind(faction) == FactionKind.Public)
                     * {
                     *  // public faction doesn't provide online status of faction members
                     * }
                     * else
                     * {*/
                    aboutPlayerCharacterFactionClanTag = FactionSystem.SharedGetClanTag(faction);
                    //}
                }
            }

            List <ICharacter> onlineStatusChangeReceivers;

            if (SharedIsListHidden)
            {
                // only server operators, moderators, and party members will receive a notification
                onlineStatusChangeReceivers = new List <ICharacter>(list.Count);
                foreach (var character in list)
                {
                    if (ServerIsOperatorOrModerator(character) ||
                        (aboutPlayerCharacterFactionClanTag is not null &&
                         string.Equals(aboutPlayerCharacterFactionClanTag,
                                       FactionSystem.SharedGetClanTag(character))) ||
                        (aboutPlayerCharacterParty is not null &&
                         ReferenceEquals(aboutPlayerCharacterParty,
                                         PartySystem.ServerGetParty(character))))
                    {
                        onlineStatusChangeReceivers.Add(character);
                    }
                }
            }
            else
            {
                // all players will receive a notification about the status change for this player
                onlineStatusChangeReceivers = list;
            }

            return(onlineStatusChangeReceivers);
        }
コード例 #10
0
        protected override bool ServerIsCompleted(ICharacter character, PlayerTaskStateWithCount state)
        {
            if (base.ServerIsCompleted(character, state))
            {
                return(true);
            }

            if (!this.IsSharedWithPartyAndFactionMembers ||
                this.TaskTarget is not IProtoQuest)
            {
                return(false);
            }

            // check whether any of the other party members has this requirement satisfied
            var currentCharacterName = character.Name;
            var partyMembers         = PartySystem.ServerGetPartyMembersReadOnly(character);

            if (partyMembers.Count > 1)
            {
                foreach (var partyMemberName in partyMembers)
                {
                    if (partyMemberName == currentCharacterName)
                    {
                        continue;
                    }

                    var partyMember = Api.Server.Characters
                                      .GetPlayerCharacter(partyMemberName);

                    if (partyMember is null)
                    {
                        continue;
                    }

                    if (partyMember.SharedGetQuests()
                        .SharedHasCompletedTask(this))
                    {
                        // party member has satisfied this requirement
                        return(true);
                    }
                }
            }

            // check whether any of the other faction members has this requirement satisfied
            if (FactionSystem.ServerGetFaction(character) is { } faction &&
                FactionSystem.SharedGetFactionKind(faction) != FactionKind.Public)
            {
                var factionMembers = FactionSystem.ServerGetFactionMembersReadOnly(faction);
                if (factionMembers.Count > 1)
                {
                    foreach (var factionMemberEntry in factionMembers)
                    {
                        var factionMemberName = factionMemberEntry.Name;
                        if (factionMemberName == currentCharacterName)
                        {
                            continue;
                        }

                        var factionMember = Api.Server.Characters
                                            .GetPlayerCharacter(factionMemberName);

                        if (factionMember is null)
                        {
                            continue;
                        }

                        if (factionMember.SharedGetQuests()
                            .SharedHasCompletedTask(this))
                        {
                            // faction member has satisfied this requirement
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }