CPQ 1 CPQ 2 CASAMENTO

This commit is contained in:
Diego Armando de Freitas Matos
2019-03-06 21:55:47 -03:00
parent 799870df63
commit 90ad58f17f
60 changed files with 17442 additions and 15142 deletions

View File

@@ -1,24 +1,24 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.world;
import client.MapleClient;
@@ -37,19 +37,20 @@ import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import server.maps.MapleDoor;
public class MapleParty {
private int id;
private MapleParty enemy = null;
private int leaderId;
private List<MaplePartyCharacter> members = new LinkedList<>();
private List<MaplePartyCharacter> pqMembers = null;
private Map<Integer, Integer> histMembers = new HashMap<>();
private int nextEntry = 0;
private Map<Integer, MapleDoor> doors = new HashMap<>();
private MonitoredReentrantLock lock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.PARTY, true);
public MapleParty(int id, MaplePartyCharacter chrfor) {
this.leaderId = chrfor.getId();
this.id = id;
@@ -103,7 +104,7 @@ public class MapleParty {
lock.unlock();
}
}
public MaplePartyCharacter getMemberById(int id) {
lock.lock();
try {
@@ -126,7 +127,7 @@ public class MapleParty {
lock.unlock();
}
}
public List<MaplePartyCharacter> getPartyMembers() {
lock.lock();
try {
@@ -135,16 +136,16 @@ public class MapleParty {
lock.unlock();
}
}
// used whenever entering PQs: will draw every party member that can attempt a target PQ while ingnoring those unfit.
public Collection<MaplePartyCharacter> getEligibleMembers() {
return Collections.unmodifiableList(pqMembers);
}
public void setEligibleMembers(List<MaplePartyCharacter> eliParty) {
pqMembers = eliParty;
}
public int getId() {
return id;
}
@@ -152,7 +153,7 @@ public class MapleParty {
public void setId(int id) {
this.id = id;
}
public int getLeaderId() {
return leaderId;
}
@@ -160,8 +161,8 @@ public class MapleParty {
public MaplePartyCharacter getLeader() {
lock.lock();
try {
for(MaplePartyCharacter mpc: members) {
if(mpc.getId() == leaderId) {
for (MaplePartyCharacter mpc : members) {
if (mpc.getId() == leaderId) {
return mpc;
}
}
@@ -171,45 +172,53 @@ public class MapleParty {
lock.unlock();
}
}
public MapleParty getEnemy() {
return enemy;
}
public void setEnemy(MapleParty enemy) {
this.enemy = enemy;
}
public List<Integer> getMembersSortedByHistory() {
List<Entry<Integer, Integer>> histList;
lock.lock();
try {
histList = new LinkedList<>(histMembers.entrySet());
} finally {
lock.unlock();
}
Collections.sort(histList, new Comparator<Entry<Integer, Integer>>()
{
@Override
public int compare( Entry<Integer, Integer> o1, Entry<Integer, Integer> o2 )
{
return ( o1.getValue() ).compareTo( o2.getValue() );
}
});
Collections.sort(histList, new Comparator<Entry<Integer, Integer>>() {
@Override
public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2) {
return (o1.getValue()).compareTo(o2.getValue());
}
});
List<Integer> histSort = new LinkedList<>();
for(Entry<Integer, Integer> e : histList) {
for (Entry<Integer, Integer> e : histList) {
histSort.add(e.getKey());
}
return histSort;
}
public byte getPartyDoor(int cid) {
List<Integer> histList = getMembersSortedByHistory();
byte slot = 0;
for(Integer e: histList) {
if(e == cid) break;
for (Integer e : histList) {
if (e == cid) {
break;
}
slot++;
}
return slot;
}
public void addDoor(Integer owner, MapleDoor door) {
lock.lock();
try {
@@ -218,33 +227,33 @@ public class MapleParty {
lock.unlock();
}
}
public void removeDoor(Integer owner) {
lock.lock();
lock.lock();
try {
this.doors.remove(owner);
} finally {
lock.unlock();
}
}
public Map<Integer, MapleDoor> getDoors() {
lock.lock();
lock.lock();
try {
return Collections.unmodifiableMap(doors);
} finally {
lock.unlock();
}
}
public void assignNewLeader(MapleClient c) {
World world = c.getWorldServer();
MaplePartyCharacter newLeadr = null;
lock.lock();
try {
for(MaplePartyCharacter mpc : members) {
if(mpc.getId() != leaderId && (newLeadr == null || newLeadr.getLevel() < mpc.getLevel())) {
for (MaplePartyCharacter mpc : members) {
if (mpc.getId() != leaderId && (newLeadr == null || newLeadr.getLevel() < mpc.getLevel())) {
newLeadr = mpc;
}
}
@@ -252,9 +261,11 @@ public class MapleParty {
lock.unlock();
}
if(newLeadr != null) world.updateParty(this.getId(), PartyOperation.CHANGE_LEADER, newLeadr);
if (newLeadr != null) {
world.updateParty(this.getId(), PartyOperation.CHANGE_LEADER, newLeadr);
}
}
public void disposeLocks() {
LockCollector.getInstance().registerDisposeAction(new Runnable() {
@Override
@@ -263,11 +274,11 @@ public class MapleParty {
}
});
}
private void emptyLocks() {
lock = lock.dispose();
}
@Override
public int hashCode() {
final int prime = 31;
@@ -276,6 +287,17 @@ public class MapleParty {
return result;
}
public MaplePartyCharacter getMemberByPos(int pos) {
int i = 0;
for (MaplePartyCharacter chr : members) {
if (pos == i) {
return chr;
}
i++;
}
return null;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {