테스트

aion-server 4.8

Gitteol
최고관리자 · 1 · 💬 0 클론/새로받기
 4.8 61f661d · 1 commits 새로받기(Pull)
game-server/src/com/aionemu/gameserver/model/team/league/LeagueService.java
package com.aionemu.gameserver.model.team.league;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.model.team.alliance.PlayerAlliance;
import com.aionemu.gameserver.model.team.common.legacy.LootGroupRules;
import com.aionemu.gameserver.model.team.common.legacy.LootRuleType;
import com.aionemu.gameserver.model.team.league.events.*;
import com.aionemu.gameserver.model.team.league.events.LeagueLeftEvent.LeaveReson;
import com.aionemu.gameserver.network.aion.serverpackets.SM_QUESTION_WINDOW;
import com.aionemu.gameserver.network.aion.serverpackets.SM_SYSTEM_MESSAGE;
import com.aionemu.gameserver.utils.PacketSendUtility;

/**
 * @author ATracer
 */
public class LeagueService {

	private static final Map<Integer, League> leagues = new ConcurrentHashMap<>();

	public static void inviteToLeague(final Player inviter, Player invited) {
		if (canInvite(inviter, invited)) {
			PlayerAlliance playerAlliance = invited.getPlayerAlliance();

			if (playerAlliance != null) {
				Player leader = playerAlliance.getLeaderObject();
				if (!leader.equals(invited)) {
					PacketSendUtility.sendPacket(inviter, SM_SYSTEM_MESSAGE.STR_UNION_INVITE_HIS_LEADER(invited.getName(), leader.getName()));
				}
				invited = leader;
			}

			LeagueInviteEvent invite = new LeagueInviteEvent(inviter, invited);
			if (invited.getResponseRequester().putRequest(SM_QUESTION_WINDOW.STR_MSGBOX_UNION_INVITE_ME, invite)) {
				PacketSendUtility.sendPacket(inviter, SM_SYSTEM_MESSAGE.STR_UNION_INVITE_HIM(invited.getName(), invited.getPlayerAlliance().size()));
				PacketSendUtility.sendPacket(invited, new SM_QUESTION_WINDOW(SM_QUESTION_WINDOW.STR_MSGBOX_UNION_INVITE_ME, 0, 0, inviter.getName()));
			}
		}
	}

	public static boolean canInvite(Player inviter, Player invited) {
		if (inviter.isDead()) {
			// You cannot use the Alliance League invitation function while you are dead.
			PacketSendUtility.sendPacket(inviter, SM_SYSTEM_MESSAGE.STR_UNION_CANT_INVITE_WHEN_DEAD());
			return false;
		} else if (!invited.isOnline()) {
			// The player you invited to the Alliance League is currently offline.
			PacketSendUtility.sendPacket(inviter, SM_SYSTEM_MESSAGE.STR_UNION_OFFLINE_MEMBER());
			return false;
		} else if (invited.getPlayerAlliance() == null) {
			// Currently, %0 cannot accept your invitation to join the alliance.
			PacketSendUtility.sendPacket(inviter, SM_SYSTEM_MESSAGE.STR_UNION_CANT_INVITE_WHEN_HE_IS_ASKED_QUESTION(invited.getName()));
			return false;
		} else if (inviter.getPlayerAlliance().hasMember(invited.getObjectId())) {
			// You cannot invite your own alliance.
			PacketSendUtility.sendPacket(inviter, SM_SYSTEM_MESSAGE.STR_UNION_CANT_INVITE_SELF());
			return false;
		} else if (invited.getPlayerAlliance().isInLeague()) {
			// The selected target is already a member of another force league.
			PacketSendUtility.sendPacket(inviter, SM_SYSTEM_MESSAGE.STR_UNION_ALREADY_MY_UNION());
			return false;
		} else if (inviter.getPlayerAlliance().isInLeague() && inviter.getPlayerAlliance().getLeague().isFull()) {
			// You cannot invite anymore as the Alliance League is full.
			PacketSendUtility.sendPacket(inviter, SM_SYSTEM_MESSAGE.STR_UNION_CANT_ADD_NEW_MEMBER());
			return false;
		} else if (inviter.getPlayerAlliance().isInLeague() && invited.getPlayerAlliance().isInLeague()
			&& inviter.getPlayerAlliance().getLeague().equals(invited.getPlayerAlliance().getLeague())) {
			// %0 is already a member of another Alliance League.
			PacketSendUtility.sendPacket(inviter, SM_SYSTEM_MESSAGE.STR_UNION_ALREADY_OTHER_UNION(invited.getName()));
			return false;
		}
		return true;
	}

	public static League createLeague(Player leader) {
		PlayerAlliance alliance = leader.getPlayerAlliance();
		Objects.requireNonNull(alliance, "Alliance can not be null");
		LeagueMember mainAlliance = new LeagueMember(alliance, 0);
		League league = new League(mainAlliance);
		league.setLootGroupRules(new LootGroupRules(LootRuleType.FREEFORALL, 0, 0, 2, 2, 2, 2, 2));
		league.addMember(mainAlliance);
		leagues.put(league.getTeamId(), league);
		league.onEvent(new LeagueCreateEvent(league));
		return league;
	}

	/**
	 * Add alliance to league
	 */
	public static void addAlliance(League league, PlayerAlliance alliance) {
		Objects.requireNonNull(league, "League should not be null");
		league.onEvent(new LeagueJoinEvent(league, alliance));
	}

	/**
	 * Remove alliance from league (normal leave)
	 */
	public static void removeAlliance(PlayerAlliance alliance) {
		if (alliance != null) {
			League league = alliance.getLeague();
			Objects.requireNonNull(league, "League should not be null");
			league.onEvent(new LeagueLeftEvent(league, alliance, LeaveReson.LEAVE));
		}
	}

	/**
	 * Remove alliance from league (expel)
	 */
	public static void expelAlliance(LeagueMember leagueAlliance, Player leagueLeader) {
		PlayerAlliance leagueLeaderAlliance = leagueLeader.getPlayerAlliance();
		if (!leagueLeaderAlliance.isLeader(leagueLeader))
			throw new IllegalArgumentException("Given player is not the league alliance leader");
		League league = leagueLeaderAlliance.getLeague();
		if (!league.isLeader(leagueLeaderAlliance))
			throw new IllegalArgumentException("Leader's alliance is not the league leader");
		league.onEvent(new LeagueLeftEvent(league, leagueAlliance.getObject(), LeaveReson.EXPEL));
	}

	public static void setLeader(Player player, Player allianceLeader) {
		PlayerAlliance alliance = player.getPlayerAlliance();
		if (alliance != null) {
			League league = alliance.getLeague();
			if (league != null)
				league.onEvent(new LeagueChangeLeaderEvent(alliance, allianceLeader));
		}
	}

	/**
	 * Disband league after minimum of members has been reached
	 */
	public static void disband(League league) {
		league.onEvent(new LeagueDisbandEvent(league));
		leagues.remove(league.getTeamId());
	}

	public static Collection<League> getLeagues() {
		return Collections.unmodifiableCollection(leagues.values());
	}

	public static void moveAlliance(Player player, int selectedId, int targetId) {
		League league = player.getPlayerAlliance().getLeague();
		if (league.getLeaderObject().getLeaderObject().equals(player)) {
			league.onEvent(new LeagueMoveEvent(league, selectedId, targetId));
		}
	}

	public static void changeGroupRules(League league, LootGroupRules lootRules) {
		league.onEvent(new LeagueLootRulesChangeEvent(league, lootRules));
	}

	public static void distributeKinah(Player player, long amount) {
		League league = player.getPlayerAlliance().getLeague();
		if (league != null) {
			league.onEvent(new LeagueKinahDistributionEvent(player, amount));
		}
	}

}

📎 첨부파일

댓글 작성 권한이 없습니다.
🏆 포인트 랭킹 TOP 10
순위 닉네임 포인트
1 no_profile 타키야겐지쪽지보내기 자기소개 아이디로 검색 전체게시물 102,949
2 no_profile 동가리쪽지보내기 자기소개 아이디로 검색 전체게시물 63,733
3 no_profile 라프텔쪽지보내기 자기소개 아이디로 검색 전체게시물 51,771
4 no_profile 불멸의행복쪽지보내기 자기소개 아이디로 검색 전체게시물 36,923
5 서번트쪽지보내기 자기소개 아이디로 검색 전체게시물 35,011
6 no_profile 닥터스쪽지보내기 자기소개 아이디로 검색 전체게시물 29,470
7 no_profile 검은고양이쪽지보내기 자기소개 아이디로 검색 전체게시물 29,077
8 no_profile Revolution쪽지보내기 자기소개 아이디로 검색 전체게시물 28,199
9 no_profile 보거스쪽지보내기 자기소개 아이디로 검색 전체게시물 26,731
10 no_profile 호롤롤로쪽지보내기 자기소개 아이디로 검색 전체게시물 17,020
알림 0