Merged with released L2J-Unity files.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.eventengine.drop;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class EventDropGroup
|
||||
{
|
||||
private final List<EventDropItem> _items = new ArrayList<>();
|
||||
private final double _chance;
|
||||
|
||||
public EventDropGroup(double chance)
|
||||
{
|
||||
_chance = chance;
|
||||
}
|
||||
|
||||
public double getChance()
|
||||
{
|
||||
return _chance;
|
||||
}
|
||||
|
||||
public List<EventDropItem> getItems()
|
||||
{
|
||||
return _items;
|
||||
}
|
||||
|
||||
public void addItem(EventDropItem item)
|
||||
{
|
||||
_items.add(item);
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.eventengine.drop;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class EventDropItem
|
||||
{
|
||||
private final int _id;
|
||||
private final int _min;
|
||||
private final int _max;
|
||||
private final double _chance;
|
||||
|
||||
public EventDropItem(int id, int min, int max, double chance)
|
||||
{
|
||||
_id = id;
|
||||
_min = min;
|
||||
_max = max;
|
||||
_chance = chance;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public int getMin()
|
||||
{
|
||||
return _min;
|
||||
}
|
||||
|
||||
public int getMax()
|
||||
{
|
||||
return _max;
|
||||
}
|
||||
|
||||
public double getChance()
|
||||
{
|
||||
return _chance;
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.eventengine.drop;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public enum EventDrops
|
||||
{
|
||||
GROUPED(GroupedDrop::new),
|
||||
NORMAL(NormalDrop::new);
|
||||
|
||||
private final Supplier<? extends IEventDrop> _supplier;
|
||||
|
||||
private EventDrops(Supplier<IEventDrop> supplier)
|
||||
{
|
||||
_supplier = supplier;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends IEventDrop> T newInstance()
|
||||
{
|
||||
return (T) (_supplier.get());
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.eventengine.drop;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jmobius.commons.util.Rnd;
|
||||
import com.l2jmobius.gameserver.model.holders.ItemHolder;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class GroupedDrop implements IEventDrop
|
||||
{
|
||||
private final List<EventDropGroup> _groups = new ArrayList<>();
|
||||
|
||||
public List<EventDropGroup> getGroups()
|
||||
{
|
||||
return _groups;
|
||||
}
|
||||
|
||||
public void addGroup(EventDropGroup group)
|
||||
{
|
||||
_groups.add(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemHolder> calculateDrops()
|
||||
{
|
||||
final List<ItemHolder> rewards = new ArrayList<>();
|
||||
for (EventDropGroup group : _groups)
|
||||
{
|
||||
if ((Rnd.nextDouble() * 100) < group.getChance())
|
||||
{
|
||||
double totalChance = 0;
|
||||
final double random = (Rnd.nextDouble() * 100);
|
||||
for (EventDropItem item : group.getItems())
|
||||
{
|
||||
totalChance += item.getChance();
|
||||
if (totalChance > random)
|
||||
{
|
||||
final long count = Rnd.get(item.getMin(), item.getMax());
|
||||
if (count > 0)
|
||||
{
|
||||
rewards.add(new ItemHolder(item.getId(), count));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rewards;
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.eventengine.drop;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.l2jmobius.gameserver.model.holders.ItemHolder;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public interface IEventDrop
|
||||
{
|
||||
public Collection<ItemHolder> calculateDrops();
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.eventengine.drop;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jmobius.commons.util.Rnd;
|
||||
import com.l2jmobius.gameserver.model.holders.ItemHolder;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class NormalDrop implements IEventDrop
|
||||
{
|
||||
private final List<EventDropItem> _items = new ArrayList<>();
|
||||
|
||||
public List<EventDropItem> getItems()
|
||||
{
|
||||
return _items;
|
||||
}
|
||||
|
||||
public void addItem(EventDropItem item)
|
||||
{
|
||||
_items.add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemHolder> calculateDrops()
|
||||
{
|
||||
final List<ItemHolder> rewards = new ArrayList<>();
|
||||
double totalChance = 0;
|
||||
final double random = (Rnd.nextDouble() * 100);
|
||||
for (EventDropItem item : _items)
|
||||
{
|
||||
totalChance += item.getChance();
|
||||
if (totalChance > random)
|
||||
{
|
||||
final long count = Rnd.get(item.getMin(), item.getMax());
|
||||
if (count > 0)
|
||||
{
|
||||
rewards.add(new ItemHolder(item.getId(), count));
|
||||
}
|
||||
}
|
||||
}
|
||||
return rewards;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user