Script integration

A few example .py scripts
Improvements on the lootservice design
This commit is contained in:
CharonInferar
2014-04-08 04:08:52 +02:00
parent 9526eee9d6
commit d848e89edb
13 changed files with 150 additions and 62 deletions
View File
View File
+8
View File
@@ -0,0 +1,8 @@
def itemTemplates():
templates=['1','2','3']
return templates
def itemChances():
return [1,2,3]
+8
View File
@@ -0,0 +1,8 @@
def itemTemplates():
templates=['1','2','3','Flawless']
return templates
def itemChances():
return [60,20,10,5]
View File
View File
View File
+4 -4
View File
@@ -11,14 +11,14 @@ def setup(core, object):
lootPoolNames_1 = ['Junk','Rifles']
lootPoolChances_1 = [90,70]
lootGroupChance_1 = 80
core.lootService.saveLootData(lootPoolNames_1,lootPoolChances_1,lootGroupChance_1)
#object.addToLootGroups(lootPoolNames_1,lootPoolChances_1,lootGroupChance_1)
#core.lootService.saveLootData(lootPoolNames_1,lootPoolChances_1,lootGroupChance_1)
object.addToLootGroups(lootPoolNames_1,lootPoolChances_1,lootGroupChance_1)
lootPoolNames2 = ['Colorcrystal']
lootPoolChances2 = [50]
lootGroupChance2 = 60
#core.lootService.saveLootData(lootPoolNames_2,lootPoolChances_2,lootGroupChance_2)
#object.addToLootGroups(lootPoolNames_2,lootPoolChances_2,lootGroupChance_2)
object.addToLootGroups(lootPoolNames_2,lootPoolChances_2,lootGroupChance_2)
#core.lootService.test3(allLootPoolNames)
return
return
+12
View File
@@ -46,4 +46,16 @@ public class LootGroup {
this.lootPoolChances = lootPoolChances;
this.lootGroupChance = lootGroupChance;
}
public String[] getLootPoolNames() {
return lootPoolNames;
}
public int[] getLootPoolChances() {
return lootPoolChances;
}
public int getLootGroupChance() {
return lootGroupChance;
}
}
+33
View File
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package resources.objects.loot;
/**
* @author Charon
*/
public class LootPool {
public LootPool(){
}
}
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package resources.objects.loot;
/**
* @author Charon
*/
public class LootRollSession {
public LootRollSession(){
}
}
@@ -453,6 +453,15 @@ public class TangibleObject extends SWGObject {
}
}
public List<LootGroup> getLootGroups() {
return lootGroups;
}
public void addToLootGroups(String[] lootPoolName, int[] lootPoolChance, int lootGroupChance) {
LootGroup lootGroup = new LootGroup(lootPoolName, lootPoolChance, lootGroupChance);
this.lootGroups.add(lootGroup);
}
@Override
public void sendBaselines(Client destination) {
@@ -477,13 +486,4 @@ public class TangibleObject extends SWGObject {
}
public List<LootGroup> getLootGroups() {
return lootGroups;
}
public void addToLootGroups(String[] lootPoolName, int[] lootPoolChance, int lootGroupChance) {
LootGroup lootGroup = new LootGroup(lootPoolName, lootPoolChance, lootGroupChance);
this.lootGroups.add(lootGroup);
}
}
+43 -49
View File
@@ -35,6 +35,8 @@ import java.util.TreeSet;
import resources.objects.creature.CreatureObject;
import resources.objects.group.GroupObject;
import resources.objects.loot.LootDrop;
import resources.objects.loot.LootGroup;
import resources.objects.loot.LootPool;
import resources.objects.player.PlayerObject;
import resources.objects.tangible.TangibleObject;
import resources.objects.tool.SurveyTool;
@@ -89,32 +91,27 @@ public class LootService implements INetworkDispatch {
}
CreatureObject lootedCreature = (CreatureObject) lootedObject;
List<LootDrop> lootDrops = new ArrayList<LootDrop>();
List<String> lootElements = new ArrayList<String>();
TreeSet<TreeMap<String,Integer>> lootSpec = lootedObject.getLootSpecification();
Iterator<TreeMap<String,Integer>> iterator = lootSpec.iterator();
//TreeSet<TreeMap<String,Integer>> lootSpec = lootedObject.getLootSpecification();
List<LootGroup> lootGroups = lootedCreature.getLootGroups();
Iterator<LootGroup> iterator = lootGroups.iterator();
while (iterator.hasNext()){
TreeMap<String,Integer> lootPool = iterator.next();
int poolProbability = lootPool.lastEntry().getValue();
int lootPoolRoll = new Random().nextInt(100);
if (lootPoolRoll <= poolProbability){
lootElements = handleLootPool(lootPool); //this lootPool will drop
LootGroup lootGroup = iterator.next();
int groupChance = lootGroup.getLootGroupChance();
int lootGroupRoll = new Random().nextInt(100);
if (lootGroupRoll <= groupChance){
handleLootGroup(lootGroup); //this lootGroup will drop something
}
}
// Now handle the chosen pools and determine the according items
for (String element : lootElements){
lootDrops = handleLootPoolElement(element);
}
// ********** Phase 1 complete, loot items determined **********
// Distribute the loot drops according to group loot rules
// Distribute the loot drops according to group loot rules
// For now just spawn items into requester's inventory
for (LootDrop dropElem : lootDrops){
PlayerObject requesterObj = (PlayerObject) requester.getSlottedObject("ghost");
@@ -125,49 +122,42 @@ public class LootService implements INetworkDispatch {
requesterInventory.add(droppedItem);
}
}
// ToDo: Group loot settings etc.
// [20:35] <@_Light> your actual loot chance was lootgroupchance*lootchance
long leaderGroupId = requester.getGroupId();
GroupObject group = (GroupObject) core.objectService.getObject(leaderGroupId);
if(group.getMemberList().size() == 1) {
// looter is alone
}
// ToDo: Group loot settings etc.
}
private List<String> handleLootPool(TreeMap<String,Integer> lootPool){
private List<String> handleLootGroup(LootGroup lootGroup){
List<String> lootElements = new ArrayList<String>();
for(Map.Entry<String,Integer> entry : lootPool.entrySet()) {
String poolElementName = entry.getKey();
int poolElementProbability = entry.getValue();
int[] lootPoolChances = lootGroup.getLootPoolChances();
String[] lootPoolNames = lootGroup.getLootPoolNames();
for(int i=0;i<lootPoolChances.length;i++) {
int lootPoolElementRoll = new Random().nextInt(100);
if (lootPoolElementRoll <= poolElementProbability){
lootElements.add(poolElementName);
if (lootPoolElementRoll <= lootPoolChances[i]){
handleLootPool(lootPoolNames[i]); // This loot pool will drop something
}
}
return lootElements;
}
private List<LootDrop> handleLootPoolElement(String element){
private List<LootDrop> handleLootPool(String poolName){
List<LootDrop> lootDropList = new ArrayList<LootDrop>();
// This is just a random element from the python
LootDrop lootDrop = new LootDrop();
// Fetch the loot pool data from the poolName.py script
String path = "scripts/lootPools/"+poolName; // + ".py";
//Vector<String> quantityList = (Vector<String>)core.scriptService.fetchStringVector(path,"resourceQuantities");
// for (String s : quantityList){
// System.out.println("OOO: " + s);
// }
//LootPool lootPool = loadfrompyreturn();
return lootDropList;
}
public void test(TreeSet test1){
}
public void test2(String test2){
System.out.println(test2);
}
public void saveLootData(String[] lootPoolName, int[] lootPoolChance, int lootGroupChance){
for (String ui : lootPoolName){
System.out.println(ui);
@@ -178,8 +168,12 @@ public class LootService implements INetworkDispatch {
System.out.println(lootGroupChance);
}
}
}
////[20:35] <@_Light> your actual loot chance was lootgroupchance*lootchance
// long leaderGroupId = requester.getGroupId();
// GroupObject group = (GroupObject) core.objectService.getObject(leaderGroupId);
// if(group.getMemberList().size() == 1) {
// // looter is alone
// }