Files
sweetgum-server/src/net/server/world/MapleParty.java
ronancpl 4c25c07e28 Mystic Doors review + Togglable SrvMessage-BossHP + Map-Event patch
Reviewed Mystic Doors.
Fixed several issues showing up on Duey in uncommon scenarios.
Fixed a concurrency issue with XMLDomMapleData.
Scheduled forward the "lock disposal" action within the source. Now, it's expected that, after a set while, no method should require usage of a disposed lock and, during that while, a supposed "disposed lock" is still available to run (although no new processes is expected to require use of these locks).
Fixed concurrency issues with player's current event instance, generating several inconsistencies when swiftly registering/unregistering from events.
Implemented a mutually exclusive approach for server message - Boss HPbar.
Fixed item-making Kage requiring lv71~80 ETC instead of the expected 81~90.
Removed the possibility to buy cosmetic coupons with mesos through the NPCs.
Sleepywood JQ's no longer gives cash items when they finish the quest repeatedly.
Added Duey trucks in several maps lacking it. Added NPC Duey in New Leaf City.
Fixed scripted quests not calculating QUEST_RATE (if applied) when rewarding experience and meso.
2018-08-07 23:37:24 -03:00

297 lines
7.9 KiB
Java

/*
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 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/>.
*/
package net.server.world;
import client.MapleClient;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Map;
import java.util.Comparator;
import net.server.audit.LockCollector;
import net.server.audit.locks.MonitoredReentrantLock;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import server.maps.MapleDoor;
public class MapleParty {
private int id;
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;
}
public boolean containsMembers(MaplePartyCharacter member) {
lock.lock();
try {
return members.contains(member);
} finally {
lock.unlock();
}
}
public void addMember(MaplePartyCharacter member) {
lock.lock();
try {
histMembers.put(member.getId(), nextEntry);
nextEntry++;
members.add(member);
} finally {
lock.unlock();
}
}
public void removeMember(MaplePartyCharacter member) {
lock.lock();
try {
histMembers.remove(member.getId());
members.remove(member);
} finally {
lock.unlock();
}
}
public void setLeader(MaplePartyCharacter victim) {
this.leaderId = victim.getId();
}
public void updateMember(MaplePartyCharacter member) {
lock.lock();
try {
for (int i = 0; i < members.size(); i++) {
if (members.get(i).getId() == member.getId()) {
members.set(i, member);
}
}
} finally {
lock.unlock();
}
}
public MaplePartyCharacter getMemberById(int id) {
lock.lock();
try {
for (MaplePartyCharacter chr : members) {
if (chr.getId() == id) {
return chr;
}
}
return null;
} finally {
lock.unlock();
}
}
public Collection<MaplePartyCharacter> getMembers() {
lock.lock();
try {
return Collections.unmodifiableList(members);
} finally {
lock.unlock();
}
}
public List<MaplePartyCharacter> getPartyMembers() {
lock.lock();
try {
return Collections.unmodifiableList(members);
} finally {
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;
}
public void setId(int id) {
this.id = id;
}
public int getLeaderId() {
return leaderId;
}
public MaplePartyCharacter getLeader() {
lock.lock();
try {
for(MaplePartyCharacter mpc: members) {
if(mpc.getId() == leaderId) {
return mpc;
}
}
return null;
} finally {
lock.unlock();
}
}
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() );
}
});
List<Integer> histSort = new LinkedList<>();
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;
slot++;
}
return slot;
}
public void addDoor(Integer owner, MapleDoor door) {
lock.lock();
try {
this.doors.put(owner, door);
} finally {
lock.unlock();
}
}
public void removeDoor(Integer owner) {
lock.lock();
try {
this.doors.remove(owner);
} finally {
lock.unlock();
}
}
public Map<Integer, MapleDoor> getDoors() {
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())) {
newLeadr = mpc;
}
}
} finally {
lock.unlock();
}
if(newLeadr != null) world.updateParty(this.getId(), PartyOperation.CHANGE_LEADER, newLeadr);
}
public void disposeLocks() {
LockCollector.getInstance().registerDisposeAction(new Runnable() {
@Override
public void run() {
emptyLocks();
}
});
}
private void emptyLocks() {
lock = lock.dispose();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final MapleParty other = (MapleParty) obj;
if (id != other.id) {
return false;
}
return true;
}
}