Database and code implementation of enemies
This commit is contained in:
parent
c8be08e5b9
commit
8bf64ec55c
@ -13,6 +13,7 @@ import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.common.util.UtilTime.TimeUnit;
|
||||
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanEnemyToken;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanToken;
|
||||
@ -51,11 +52,11 @@ public class ClanInfo
|
||||
private long _dateCreated = 0;
|
||||
private long _lastOnline = 0;
|
||||
|
||||
private NautHashMap<String, Boolean> _allyMap = new NautHashMap<String, Boolean>();
|
||||
|
||||
// Loaded from Client
|
||||
private NautHashMap<String, Role> _memberMap = new NautHashMap<String, Role>();
|
||||
private NautHashMap<String, Boolean> _allyMap = new NautHashMap<String, Boolean>();
|
||||
private HashSet<String> _claimSet = new HashSet<String>();
|
||||
private EnemyData _enemyData;
|
||||
|
||||
// Temporary
|
||||
private NautHashMap<String, Long> _inviteeMap = new NautHashMap<String, Long>();
|
||||
@ -102,6 +103,9 @@ public class ClanInfo
|
||||
{
|
||||
_allyMap.put(allianceToken.ClanName, allianceToken.Trusted);
|
||||
}
|
||||
|
||||
ClanEnemyToken enemyToken = token.EnemyToken;
|
||||
_enemyData = new EnemyData(enemyToken.EnemyName, enemyToken.Initiator, enemyToken.Score, enemyToken.Kills);
|
||||
}
|
||||
|
||||
public int getClaims()
|
||||
@ -408,6 +412,16 @@ public class ClanInfo
|
||||
{
|
||||
return _energy;
|
||||
}
|
||||
|
||||
public EnemyData getEnemyData()
|
||||
{
|
||||
return _enemyData;
|
||||
}
|
||||
|
||||
public boolean hasEnemy()
|
||||
{
|
||||
return _enemyData != null;
|
||||
}
|
||||
|
||||
public void adjustEnergy(int energy)
|
||||
{
|
||||
|
@ -271,6 +271,21 @@ public class ClansDataAccessLayer
|
||||
//Log
|
||||
_manager.log("Set Home for [" + clan.getName() + "] to " + UtilWorld.locToStrClean(loc) + " by [" + player + "].");
|
||||
}
|
||||
|
||||
public void updateEnemy(ClanInfo clan, ClanInfo otherClan)
|
||||
{
|
||||
assert clan.getEnemyData() != null && otherClan.getEnemyData() != null;
|
||||
assert clan.getEnemyData().getEnemyName() == otherClan.getName() && otherClan.getEnemyData().getEnemyName() == clan.getName();
|
||||
|
||||
ClanInfo initiator = clan.getEnemyData().isInitiator() ? clan : otherClan;
|
||||
EnemyData iData = initiator.getEnemyData();
|
||||
ClanInfo other = clan == initiator ? otherClan : clan;
|
||||
EnemyData oData = other.getEnemyData();
|
||||
_repository.updateEnemy(initiator.getId(), other.getId(), iData.getScore(), oData.getScore(), iData.getKills(), oData.getKills());
|
||||
|
||||
//Log
|
||||
_manager.log("Updated Enemy Data for [" + clan.getName() + ", " + otherClan.getName() + "]");
|
||||
}
|
||||
|
||||
public void updateEnergy(ClanInfo clan)
|
||||
{
|
||||
|
@ -35,6 +35,7 @@ import mineplex.game.clans.clans.commands.ClansAllyChatCommand;
|
||||
import mineplex.game.clans.clans.commands.ClansChatCommand;
|
||||
import mineplex.game.clans.clans.commands.ClansCommand;
|
||||
import mineplex.game.clans.clans.repository.ClanTerritory;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanEnemyToken;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanToken;
|
||||
|
@ -0,0 +1,37 @@
|
||||
package mineplex.game.clans.clans;
|
||||
|
||||
public class EnemyData
|
||||
{
|
||||
private String _enemy;
|
||||
private boolean _initiator;
|
||||
private int _score;
|
||||
private int _kills;
|
||||
|
||||
public EnemyData(String enemy, boolean initiator, int score, int kills)
|
||||
{
|
||||
_enemy = enemy;
|
||||
_initiator = initiator;
|
||||
_score = score;
|
||||
_kills = kills;
|
||||
}
|
||||
|
||||
public String getEnemyName()
|
||||
{
|
||||
return _enemy;
|
||||
}
|
||||
|
||||
public int getScore()
|
||||
{
|
||||
return _score;
|
||||
}
|
||||
|
||||
public int getKills()
|
||||
{
|
||||
return _kills;
|
||||
}
|
||||
|
||||
public boolean isInitiator()
|
||||
{
|
||||
return _initiator;
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ import mineplex.core.database.column.ColumnLong;
|
||||
import mineplex.core.database.column.ColumnVarChar;
|
||||
import mineplex.game.clans.clans.ClanInfo;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanEnemyToken;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken;
|
||||
import mineplex.game.clans.clans.repository.tokens.ClanToken;
|
||||
@ -29,6 +30,7 @@ public class ClanRepository extends RepositoryBase
|
||||
private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.dateCreated, c.lastOnline, ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverName = ?;";
|
||||
private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE c.serverName = ?;";
|
||||
private static String RETRIEVE_CLAN_ALLIANCE_INFO = "SELECT c.name, cOther.name, ca.trusted FROM clanAlliances AS ca INNER JOIN clans AS c ON c.id = ca.clanId INNER JOIN clans as cOther ON cOther.id = ca.otherClanId WHERE c.serverName = ?;";
|
||||
private static String RETRIEVE_CLAN_ENEMY_INFO = "SELECT c.name, cOther.name, clanScore, otherClanScore, clanKills, otherClanKills FROM clanEnemies AS ce INNER JOIN clans AS c ON c.id = ce.clanId INNER JOIN clans as cOther ON cOther.id = ce.otherClanId WHERE c.serverName = ?;";
|
||||
|
||||
private static String DELETE_CLAN_MEMBER = "DELETE aC FROM accountClan AS aC INNER JOIN accounts ON accounts.id = aC.accountId WHERE aC.clanId = ? AND accounts.name = ?;";
|
||||
private static String DELETE_CLAN_MEMBERS = "DELETE FROM accountClan WHERE clanId = ?;";
|
||||
@ -36,16 +38,19 @@ public class ClanRepository extends RepositoryBase
|
||||
private static String DELETE_CLAN_TERRITORIES = "DELETE FROM clanTerritory WHERE clanId = ?;";
|
||||
private static String DELETE_CLAN_ALLIANCE = "DELETE FROM clanAlliances WHERE clanId = ? AND otherClanId = ?;";
|
||||
private static String DELETE_CLAN_ALLIANCES = "DELETE FROM clanAlliances WHERE clanId = ? OR otherClanId = ?;";
|
||||
private static String DELETE_CLAN_ENEMY = "DELETE FROM clanEnemies WHERE clanId = ? OR otherClanId = ?;";
|
||||
private static String DELETE_CLAN = "DELETE FROM clans WHERE id = ?;";
|
||||
|
||||
private static String ADD_CLAN = "INSERT INTO clans (serverName, name, description, home, admin, dateCreated, energy, lastOnline) VALUES (?, ?, ?, ?, ?, now(), ?, now());";
|
||||
private static String ADD_CLAN_MEMBER = "INSERT INTO accountClan (accountId, clanId, clanRole) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.name = ?;";
|
||||
private static String ADD_CLAN_ALLIANCE = "INSERT INTO clanAlliances (clanId, otherClanId, trusted) VALUES (?, ?, ?);";
|
||||
private static String ADD_CLAN_ENEMY = "INSERT INTO clanEnemies (clanId, otherClanId, timeFormed) VALUES (?, ?, now());";
|
||||
private static String ADD_CLAN_TERRITORY = "INSERT INTO clanTerritory (clanId, serverName, chunk, safe) VALUES (?, ?, ?, ?);";
|
||||
|
||||
private static String UPDATE_CLAN = "UPDATE clans SET name = ?, description = ?, home = ?, admin = ?, energy = ?, lastOnline = ? WHERE id = ?;";
|
||||
private static String UPDATE_CLAN_MEMBER = "UPDATE accountClan AS AC INNER JOIN accounts ON accounts.id = AC.accountId SET AC.clanRole = ? WHERE AC.clanId = ? AND accounts.name = ?;";
|
||||
private static String UPDATE_CLAN_ALLIANCE = "UPDATE clanAlliances SET trusted = ? WHERE clanId = ? AND otherClanId = ?;";
|
||||
private static String UPDATE_CLAN_ENEMY = "UPDATE clanEnemies SET clanScore = ?, otherClanScore = ?, clanKills = ?, otherClanKills = ? WHERE clanId = ? AND otherClanId = ?;";
|
||||
private static String UPDATE_CLAN_TERRITORY = "UPDATE clanTerritory SET safe = ? WHERE serverName = ? AND chunk = ?;";
|
||||
|
||||
private String _serverName;
|
||||
@ -147,6 +152,41 @@ public class ClanRepository extends RepositoryBase
|
||||
}
|
||||
|
||||
}, new ColumnVarChar("serverName", 100, _serverName));
|
||||
|
||||
executeQuery(RETRIEVE_CLAN_ENEMY_INFO, new ResultSetCallable()
|
||||
{
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
while (resultSet.next())
|
||||
{
|
||||
ClanEnemyToken clanToken = new ClanEnemyToken();
|
||||
ClanEnemyToken otherClanToken = new ClanEnemyToken();
|
||||
|
||||
//c.name, cOther.name, clanScore, otherClanScore, clanKills, otherClanKills
|
||||
String clanName = resultSet.getString(1);
|
||||
String otherClanName = resultSet.getString(2);
|
||||
int clanScore = resultSet.getInt(3);
|
||||
int otherClanScore = resultSet.getInt(4);
|
||||
int clanKills = resultSet.getInt(5);
|
||||
int otherClanKills = resultSet.getInt(6);
|
||||
|
||||
clanToken.EnemyName = otherClanName;
|
||||
clanToken.Score = clanScore;
|
||||
clanToken.Kills = clanKills;
|
||||
clanToken.Initiator = true;
|
||||
|
||||
otherClanToken.EnemyName = clanName;
|
||||
otherClanToken.Score = otherClanScore;
|
||||
otherClanToken.Kills = otherClanKills;
|
||||
otherClanToken.Initiator = false;
|
||||
|
||||
clans.get(clanName).EnemyToken = clanToken;
|
||||
clans.get(otherClanName).EnemyToken = otherClanToken;
|
||||
}
|
||||
}
|
||||
|
||||
}, new ColumnVarChar("serverName", 100, _serverName));
|
||||
|
||||
return clans.values();
|
||||
}
|
||||
@ -161,6 +201,7 @@ public class ClanRepository extends RepositoryBase
|
||||
executeUpdate(DELETE_CLAN_MEMBERS, new ColumnInt("clanid", clanId));
|
||||
executeUpdate(DELETE_CLAN_TERRITORIES, new ColumnInt("clanid", clanId));
|
||||
executeUpdate(DELETE_CLAN_ALLIANCES, new ColumnInt("clanid", clanId), new ColumnInt("clanid", clanId));
|
||||
executeUpdate(DELETE_CLAN_ENEMY, new ColumnInt("clanid", clanId));
|
||||
executeUpdate(DELETE_CLAN, new ColumnInt("clanid", clanId));
|
||||
}
|
||||
|
||||
@ -226,6 +267,13 @@ public class ClanRepository extends RepositoryBase
|
||||
executeUpdate(UPDATE_CLAN, new ColumnVarChar("name", 100, name), new ColumnVarChar("desc", 100, desc), new ColumnVarChar("home", 100, home), new ColumnBoolean("admin", admin), new ColumnInt("energy", energy), new ColumnLong("lastOnline", lastOnline), new ColumnInt("clanId", clanId));
|
||||
}
|
||||
|
||||
public void updateEnemy(int clanId, int otherClanId, int clanScore, int otherClanScore, int clanKills, int otherClanKills)
|
||||
{
|
||||
executeUpdate(UPDATE_CLAN_ENEMY, new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId),
|
||||
new ColumnInt("clanScore", clanScore), new ColumnInt("otherClanScore", otherClanScore), new ColumnInt("clanKills", clanKills),
|
||||
new ColumnInt("otherClanKills", otherClanKills), new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId));
|
||||
}
|
||||
|
||||
public void updateTerritoryClaim(String chunk, boolean safe)
|
||||
{
|
||||
executeUpdate(UPDATE_CLAN_TERRITORY, new ColumnBoolean("safe", safe), new ColumnVarChar("serverName", 100, _serverName), new ColumnVarChar("chunk", 100, chunk));
|
||||
|
@ -0,0 +1,9 @@
|
||||
package mineplex.game.clans.clans.repository.tokens;
|
||||
|
||||
public class ClanEnemyToken
|
||||
{
|
||||
public boolean Initiator;
|
||||
public String EnemyName;
|
||||
public int Score;
|
||||
public int Kills;
|
||||
}
|
@ -13,6 +13,8 @@ public class ClanToken
|
||||
public int Energy;
|
||||
public long DateCreated;
|
||||
public long LastOnline;
|
||||
|
||||
public ClanEnemyToken EnemyToken;
|
||||
|
||||
public List<ClanMemberToken> Members = new ArrayList<ClanMemberToken>();
|
||||
public List<ClanTerritoryToken> Territories = new ArrayList<ClanTerritoryToken>();
|
||||
|
Loading…
Reference in New Issue
Block a user