import java.util.*; public class SpellBook{ Hashtable existingSpells = new Hashtable(); //all existing spells Hashtable spells = new Hashtable(); //spells available to client Vector spellCasts = new Vector(); //spells cast this turn ResearchSpell[] researchSpells = new ResearchSpell[8]; ValueBar manaResearch; int investment; //Knowledge in different Areas int GAIASLORE = 1; //Eftersom man har grow1 från början int NECROMANCY=0; int MENTALISM=0; int ILLUSIONS=0; int EVILEYE=0; int ORACLE=0; public SpellBook() { super(); init(); manaResearch = new ValueBar("Mana invest",0,true); } /** * Given a string without any newlines, such are added at appropriate places. */ public String formatDescription(String desc){ int LINE_LEN = 60; StringTokenizer st = new StringTokenizer(desc); String msg = ""; int pos=0; while(st.hasMoreTokens()) { String s = st.nextToken(); pos += s.length(); if (pos > LINE_LEN) { pos = s.length(); msg += "\n" + s + " "; } else msg += s + " "; } return msg; } public String toString(){ String str = "Spells\n======\n"; Enumeration e = spells.elements(); while(e.hasMoreElements()) str +=((Spell)e.nextElement()).getSpellName()+"\n"; return str; } public void init(){ //Lägg till alla besvärjelser som finns spells.put((new Grow1()).getSpellName(),new Grow1()); // spells.put((new ManaGrow1()).getSpellName(),new ManaGrow1()); //Oracle add(new SpyArea1()); add(new SpyArea2()); //Necromancy add(new Animate1()); add(new Animate2()); add(new KillDragon1()); add(new KillDragon2()); add(new KillDragon3()); add(new KillCity1()); add(new KillCity2()); add(new KillCity3()); add(new KillCity4()); //Illusion add(new Confuse1()); add(new Confuse2()); add(new Fake1()); add(new Fake2()); //Evil eye add(new Weakness1()); add(new Weakness2()); add(new Settmod1()); add(new Settmod2()); //Gaia add(new Grow1()); add(new Grow2()); add(new Grow3()); add(new GrowDragon1()); add(new DragonLoc1()); add(new DragonLoc2()); add(new DragonLoc3()); //Mentalism add(new Enhance1()); add(new Enhance2()); add(new Control1()); add(new Control2()); add(new ManaGrow1()); add(new ManaGrow2()); } private void add(Spell sp) { existingSpells.put(sp.getSpellName(),sp); // spells.put(sp.getSpellName(),sp); } public void research(ClientThread ct){ int nrOfSpells= 0; for(int i=0;i ct.mana.getValue()) manaResearch.setValue(ct.mana.getValue()); if(investment > ct.money) investment = ct.money; ct.mana.setValue(ct.mana.getValue()-manaResearch.getValue()); ct.process.researchcosts = investment; int investmentPerSpell = (investment + 25*manaResearch.getValue())/nrOfSpells; System.out.println("Inv:"+investment+" Nr:"+nrOfSpells+" per:"+investmentPerSpell); for(int i=0;i= (s.getLevel()*(s.getLevel()-1))/2; } else if(school.equals("Necromancy")) return NECROMANCY >= (s.getLevel()*(s.getLevel()-1))/2; else if(school.equals("Mentalism")) return MENTALISM >= (s.getLevel()*(s.getLevel()-1))/2; else if(school.equals("Illusions")){ System.out.println("SK:"+ILLUSIONS+" Slvl:"+(s.getLevel()*(s.getLevel()-1))/2); return ILLUSIONS >= (s.getLevel()*(s.getLevel()-1))/2; } else if(school.equals("Evil Eye")) return EVILEYE >= (s.getLevel()*(s.getLevel()-1))/2; else if(school.equals("Oracle")) return ORACLE >= (s.getLevel()*(s.getLevel()-1))/2; else{ System.out.println("STRANGE SCHOOL"); return true; } } public static void main(String[] arg){ SpellBook sb = new SpellBook(); sb.init(); System.out.println(sb.toString()); System.out.println(sb.formatDescription("hej detta är en himla lång sträng som definitivt pehover formateras eller hur..!??")); } }