private static void ServerResetDecayTimerForLandClaimAreasGroup(ILogicObject areasGroup) { var areasGroupPrivateState = LandClaimAreasGroup.GetPrivateState(areasGroup); var areasGroupPublicState = LandClaimAreasGroup.GetPublicState(areasGroup); var areas = areasGroupPrivateState.ServerLandClaimsAreas; // TODO: it's better to move this code to another place as this property is used in several other places areasGroupPublicState.IsFounderDemoPlayer = ServerGetIsFounderDemoPlayer(areas); // reset the decay timer for all land claim buildings inside this areas group var decayDelayDuration = LandClaimSystem.ServerGetDecayDelayDurationForLandClaimAreas( areas, areasGroupPublicState.IsFounderDemoPlayer, out _); foreach (var area in areas) { var worldObject = LandClaimArea.GetPrivateState(area) .ServerLandClaimWorldObject; StructureDecaySystem.ServerResetDecayTimer( worldObject.GetPrivateState <StructurePrivateState>(), decayDelayDuration); } }
// Iterate over all not-visited neighbor areas of this owner and reset their decay timers, recursively. private static void ServerResetDecayTimerRecursively( List <ILogicObject> visitedAreas, RectangleInt currentAreaBounds, ICharacter character) { using (var tempList = Api.Shared.GetTempList <ILogicObject>()) { LandClaimSystem.SharedGetAreasInBounds(currentAreaBounds.Inflate(1, 1), tempList); foreach (var otherArea in tempList) { if (visitedAreas.Contains(otherArea)) { continue; } visitedAreas.Add(otherArea); if (!LandClaimSystem.ServerIsOwnedArea(otherArea, character)) { continue; } var worldObject = otherArea.GetPrivateState <LandClaimAreaPrivateState>().ServerLandClaimWorldObject; StructureDecaySystem.ServerResetDecayTimer( worldObject.GetPrivateState <StructurePrivateState>()); var otherAreaBounds = LandClaimSystem.SharedGetLandClaimAreaBounds(otherArea); ServerResetDecayTimerRecursively(visitedAreas, otherAreaBounds, character); } } }
public static void ServerRefreshLandClaimObject(IStaticWorldObject worldObject) { if (worldObject.IsDestroyed) { return; } if (!(worldObject.ProtoStaticWorldObject is IProtoObjectLandClaim)) { // not a land claim structure return; } var area = LandClaimSystem.ServerGetLandClaimArea(worldObject); if (area == null) { // incorrect land claim - no area attached return; } var areaBounds = LandClaimSystem.SharedGetLandClaimAreaBounds(area); var owners = LandClaimArea.GetPrivateState(area).LandOwners; foreach (var owner in owners) { var character = Server.Characters.GetPlayerCharacter(owner); if (character == null || !character.IsOnline) { continue; } if (!areaBounds.Contains(character.TilePosition)) { continue; } // the land claim contains an online owner character // reset the decay timer for this land claim StructureDecaySystem.ServerResetDecayTimer( worldObject.GetPrivateState <StructurePrivateState>()); using (var tempVisitedAreas = Api.Shared.WrapObjectInTempList(area)) { ServerResetDecayTimerRecursively(tempVisitedAreas.AsList(), areaBounds, character); } return; } }
private static void ServerRefreshLandClaimAreasGroup(ILogicObject areasGroup) { var areas = LandClaimAreasGroup.GetPrivateState(areasGroup).ServerLandClaimsAreas; foreach (var area in areas) { var areaBounds = LandClaimSystem.SharedGetLandClaimAreaBounds(area, addGracePadding: true); var owners = LandClaimArea.GetPrivateState(area).LandOwners; foreach (var owner in owners) { var character = Server.Characters.GetPlayerCharacter(owner); if (character == null || !character.ServerIsOnline) { continue; } if (!areaBounds.Contains(character.TilePosition)) { continue; } // the land claim area contains an online owner character ServerResetDecayTimer(); return; } } // helper method to reset the decay timer for all land claim buildings inside this areas group void ServerResetDecayTimer() { var decayDelayDuration = LandClaimSystem.ServerGetDecayDelayDurationForLandClaimAreas(areas); foreach (var area in areas) { var worldObject = LandClaimArea.GetPrivateState(area) .ServerLandClaimWorldObject; StructureDecaySystem.ServerResetDecayTimer( worldObject.GetPrivateState <StructurePrivateState>(), decayDelayDuration); } } }
private static void ServerRefreshLandClaimAreasGroup(ILogicObject areasGroup) { if (areasGroup.IsDestroyed) { return; } var areasGroupPrivateState = LandClaimAreasGroup.GetPrivateState(areasGroup); var areasGroupPublicState = LandClaimAreasGroup.GetPublicState(areasGroup); var areas = areasGroupPrivateState.ServerLandClaimsAreas; // TODO: it's better to move this code to another place as this property is used in several other places areasGroupPublicState.IsFounderDemoPlayer = ServerGetIsFounderDemoPlayer(areas); // check every area in the group // if any of them has an online owner, reset the decay timer foreach (var area in areas) { var areaBounds = LandClaimSystem.SharedGetLandClaimAreaBounds(area, addGracePadding: true); var areaPrivateState = LandClaimArea.GetPrivateState(area); var owners = areaPrivateState.LandOwners; foreach (var owner in owners) { var character = ServerCharacters.GetPlayerCharacter(owner); if (character is null || !character.ServerIsOnline) { continue; } if (!areaBounds.Contains(character.TilePosition)) { continue; } // the land claim area contains an online owner character ServerResetDecayTimer(); return; } } // helper method to reset the decay timer for all land claim buildings inside this areas group void ServerResetDecayTimer() { var decayDelayDuration = LandClaimSystem.ServerGetDecayDelayDurationForLandClaimAreas( areas, areasGroupPublicState.IsFounderDemoPlayer, out _); foreach (var area in areas) { var worldObject = LandClaimArea.GetPrivateState(area) .ServerLandClaimWorldObject; StructureDecaySystem.ServerResetDecayTimer( worldObject.GetPrivateState <StructurePrivateState>(), decayDelayDuration); } } }