瀏覽代碼

Actually working descriptions.
Improved way of creating descriptions, no longer have to create a thousand descritions.

Reddo 5 年之前
父節點
當前提交
05523e1ede

+ 2 - 2
app/Elements/Classes/AnimationLayer.ts

@@ -38,12 +38,12 @@ class AnimationLayer {
         this.el.style.marginLeft = "-" + this.frameSize/2 + "px";
         this.el.style.marginTop = "-" + ((this.frameSize / 2)) + "px";
         if (this.heightMult != 1) {
-            let realHeight = this.heightMult * (Elements.AnimationHandler.spriteSize / this.frameSize) * this.frameSize;
+            //let realHeight = this.heightMult * (Elements.AnimationHandler.spriteSize / this.frameSize) * this.frameSize;
             this.el.style.top = "100%";
             this.el.style.marginTop = (- (this.feetHeight - (this.feetHeight * this.heightMult))) + "px";
             //this.el.style.top = "100%";
             //this.el.style.marginTop = "-" + (realHeight + this.feetHeight);
-            console.log("finalHeight: ", realHeight, "feetHeight:", this.feetHeight, "target:" , 130, this.el.style.marginTop);
+            //console.log("finalHeight: ", realHeight, "feetHeight:", this.feetHeight, "target:" , 130, this.el.style.marginTop);
             // Originally top: 50%;
         }
     }

+ 3 - 6
app/World/Classes/Action.ts

@@ -181,9 +181,10 @@ Action.check.addRule(
     })
 );
 
+// TODO: Pass everything on here directly to the AI so that IT can handle this.
 Action.carry.addRule(
     new Rule({
-        name : "Check any Action - Requires Visibility",
+        name : "Check any Action - Angery",
         firstPriority : Rule.PRIORITY_LOWEST,
         priority: Rule.PRIORITY_LOWEST,
         code : (rulebook : RulebookRunner<Action>) => {
@@ -202,11 +203,7 @@ Action.carry.addRule(
             }
 
 
-            action.say.add(Say.PARAGRAPH_BREAK, ...CombatDescription.getDescription(new ContentGroup(cu)));
-
-            action.say.getHTML("p", [], true).then((result:[HTMLElement])=> {
-                console.log(result[0].innerText);
-            });
+            action.say.add(Say.PARAGRAPH_BREAK, ...CombatPokeDescription.getDescription(new ContentGroup(cu)));
         },
         conditions : (rulebook : RulebookRunner<Action>) => {
             let action = <Action> rulebook.noun;

+ 26 - 19
app/World/Classes/Action/ActionAttack.ts

@@ -75,8 +75,7 @@ class ActionAttack extends Action {
         return "attack " + this.getNoun(0).getPrintedName() + " with " + weaponName;
     }
 
-    public generateDescription (...cu : Array<CombatUnit>) {
-        let group = new ContentGroup(...cu);
+    public generateDescription (group : ContentGroup) {
         this.say.add(...(CombatDescription.getDescription(group)));
     }
 
@@ -140,11 +139,14 @@ class ActionAttack extends Action {
                 defense += targetDex;
                 if (attack < defense) {
                     action.generateDescription(
-                        (new CombatUnit())
-                            .setActor(action.actor)
-                            .setTarget(target)
-                            .setWeapon(...action.getWeapons())
-                            .addMarker(CombatHit.MISS)
+                        (new ContentGroup())
+                            .addUnit(
+                                (new CombatUnit())
+                                    .setActor(action.actor)
+                                    .setTarget(target)
+                                    .setWeapon(...weapons)
+                                    .addMarker(CombatHit.MISS)
+                            )
                     );
                     return false;
                 }
@@ -170,12 +172,14 @@ class ActionAttack extends Action {
                 if (target.breakable && target.breakableOn <= damage) {
                     target.break();
                     action.generateDescription(
-                        (new CombatUnit())
-                            .setActor(action.actor)
-                            .setTarget(target)
-                            .setWeapon(...weapons)
-                            .addMarker(CombatHit.HIT)
-                            .addMarker(CombatResult.KILLED)
+                        (new ContentGroup())
+                            .addUnit(
+                                (new CombatUnit())
+                                    .setActor(action.actor)
+                                    .setTarget(target)
+                                    .setWeapon(...weapons)
+                                    .addMarker(CombatHit.HIT, CombatResult.KILLED)
+                            )
                     );
                 }
             } else {
@@ -208,13 +212,16 @@ class ActionAttack extends Action {
                     target.die();
                 }
 
+
                 action.generateDescription(
-                    (new CombatUnit())
-                        .setActor(action.actor)
-                        .setTarget(target)
-                        .setWeapon(...weapons)
-                        .addMarker(hitType)
-                        .addMarker(result)
+                    (new ContentGroup())
+                        .addUnit(
+                            (new CombatUnit())
+                                .setActor(action.actor)
+                                .setTarget(target)
+                                .setWeapon(...weapons)
+                                .addMarker(hitType, result)
+                        )
                 );
             }
         }

+ 58 - 0
app/World/Classes/ContentPicker/AdaptiveDifferential.ts

@@ -0,0 +1,58 @@
+class AdaptiveDifferential {
+    public compareFunction : (noun : any) => boolean = () => false;
+    public countsAs = 0;
+
+    constructor (replacer : (noun : any) => boolean) {
+        this.compareFunction = replacer;
+    }
+
+    public isMatch (noun : any) {
+        return this.compareFunction(noun);
+    }
+
+    public static ANYOF (...acceptableValues) {
+        return new AdaptiveDifferential((noun : any) => {
+            //console.log(acceptableValues, noun);
+            for (let i = 0; i < acceptableValues.length; i++) {
+                if (ContentDifferential.compareNouns(acceptableValues[i], noun)) {
+                    return true;
+                }
+            }
+            return false;
+        });
+    }
+
+    public static FULLYADAPTIVE (...acceptableValues) {
+        let ad = AdaptiveDifferential.ANYOF(...acceptableValues);
+        ad.countsAs = -1;
+        return ad;
+    }
+
+    public static MALE = new AdaptiveDifferential((noun : any) => {
+        if (noun instanceof Humanoid) {
+            return noun.isMale();
+        }
+        return false;
+    });
+
+    public static FEMALE = new AdaptiveDifferential((noun : any) => {
+        if (noun instanceof Humanoid) {
+            return noun.isMale();
+        }
+        return false;
+    });
+
+    public static MASCULINE = new AdaptiveDifferential((noun : any) => {
+        if (noun instanceof Humanoid) {
+            return noun.getGenderValue().genderValueCorrected <= 50;
+        }
+        return false;
+    });
+
+    public static FEMININE = new AdaptiveDifferential((noun : any) => {
+        if (noun instanceof Humanoid) {
+            return noun.getGenderValue().genderValueCorrected >= 50;
+        }
+        return false;
+    });
+}

+ 10 - 6
app/World/Classes/ContentPicker/Combat/CombatDescription.ts

@@ -30,14 +30,18 @@ class CombatDescription extends ContentDescription {
         CombatDescription.DESCRIPTIONS.push(this);
     }
 
-    public addUnit () {
-        let unit = new CombatUnit();
-        (<ContentGroup> this.group).addUnit(unit);
-        return unit;
+    public setDescriptionFunction (descriptionFor : (actor : any, target : any, weapons : Array<any>, markers : Array<any>) => Say) {
+        let finalFunction = (description : CombatDescription, group : ContentGroup) => {
+            // Combat only has one unit
+            let unit = <CombatUnit> group.getUnit(0);
+            return descriptionFor (unit.getActor().nouns[0], unit.getTarget().nouns[0], unit.getWeapons(), unit.getMarkers());
+        }
+        this.description = finalFunction;
+        return this;
     }
 
-    public addPokeUnit () {
-        let unit = new CombatPokeUnit();
+    public addUnit () {
+        let unit = new CombatUnit();
         (<ContentGroup> this.group).addUnit(unit);
         return unit;
     }

+ 35 - 0
app/World/Classes/ContentPicker/Combat/CombatPokeDescription.ts

@@ -0,0 +1,35 @@
+/// <reference path="../ContentDescription.ts" />
+/// <reference path="CombatPokeUnit.ts" />
+/// <reference path="CombatUnit.ts" />
+/**
+ * Quick Cheat Sheet of markers!
+
+ */
+class CombatPokeDescription extends ContentDescription {
+    public static DESCRIPTIONS = [];
+
+    public constructor (name : string) {
+        super(name, new ContentGroup());
+        CombatPokeDescription.DESCRIPTIONS.push(this);
+    }
+
+    public setDescriptionFunction (descriptionFor : (target : any, markers : Array<any>) => Say) {
+        let finalFunction = (description : CombatPokeDescription, group : ContentGroup) => {
+            // Combat only has one unit
+            let unit = <CombatPokeUnit> group.getUnit(0);
+            return descriptionFor (unit.getTarget().nouns[0], unit.getMarkers());
+        }
+        this.description = finalFunction;
+        return this;
+    }
+
+    public addUnit () {
+        let unit = new CombatPokeUnit();
+        (<ContentGroup> this.group).addUnit(unit);
+        return unit;
+    }
+
+    public static getDescription (target : ContentGroup) {
+        return ContentDescription.pickDescriptions(CombatPokeDescription.DESCRIPTIONS, target);
+    }
+}

+ 12 - 2
app/World/Classes/ContentPicker/Combat/CombatPokeUnit.ts

@@ -16,18 +16,28 @@ class CombatPokeUnit extends ContentUnit {
         return this;
     }
 
+    public getTarget () {
+        return this.target;
+    }
+
 
-    public addMarker (marker : ContentMarker) {
-        this.markers.addNoun(marker);
+    public addMarker (...marker : Array<ContentMarker | AdaptiveDifferential>) {
+        this.markers.addNoun(...marker);
         return this;
     }
 
+    public getMarkers () {
+        return [...this.markers.nouns];
+    }
+
     public getScore () {
         return this.target.getScore() + this.markers.getScore();
     }
 
     public isMatch (cu : CombatPokeUnit) {
+        console.warn("Chegking :)");
         if (cu instanceof CombatPokeUnit) {
+            console.log(this.markers.nouns, cu.markers.nouns);
             return this.target.isMatch(cu.target) &&
                 this.markers.isMatch(cu.markers);
         }

+ 19 - 3
app/World/Classes/ContentPicker/Combat/CombatUnit.ts

@@ -5,7 +5,7 @@
 class CombatUnit extends ContentUnit {
 	private actor : ContentDifferential = new ContentDifferential(Person);
 	private target : ContentDifferential = new ContentDifferential(Person);
-	private weapon : ContentDifferential = new ContentDifferential(Thing);
+	private weapon : ContentDifferential = new ContentDifferential();
 	private markers : ContentDifferential = new ContentDifferential();
 
 	public constructor () {
@@ -17,21 +17,37 @@ class CombatUnit extends ContentUnit {
 		return this;
 	}
 
+	public getActor () {
+		return this.actor;
+	}
+
 	public setTarget (it : Thing | typeof Thing) {
 		this.target = new ContentDifferential(it);
 		return this;
 	}
 
+	public getTarget () {
+		return this.target;
+	}
+
 	public setWeapon (...it : Array<Thing | typeof Thing>) {
 		this.weapon = new ContentDifferential(...it);
 		return this;
 	}
 
-	public addMarker (marker : ContentMarker) {
-		this.markers.addNoun(marker);
+	public getWeapons () {
+		return [...this.weapon.nouns];
+	}
+
+	public addMarker (...marker : Array<ContentMarker | AdaptiveDifferential>) {
+		this.markers.addNoun(...marker);
 		return this;
 	}
 
+	public getMarkers () {
+		return [...this.markers.nouns];
+	}
+
 	public getScore () {
 		return this.actor.getScore() + this.target.getScore() + this.weapon.getScore() + this.markers.getScore();
 	}

+ 10 - 0
app/World/Classes/ContentPicker/ContentDescription.ts

@@ -9,6 +9,16 @@ class ContentDescription {
         this.group = group;
     }
 
+    public addMarker (marker : any) {
+        if (this.group instanceof ContentGroup) {
+            let markerUnit = new ContentUnit();
+            markerUnit.addCategory(new ContentDifferential(marker))
+            this.group.addUnit(markerUnit);
+        } else if (this.group instanceof ContentUnit) {
+            this.group.addCategory(marker);
+        }
+    }
+
     public getScore () {
         return (this.group).getScore();
     }

+ 12 - 3
app/World/Classes/ContentPicker/ContentDifferential.ts

@@ -32,9 +32,15 @@ class ContentDifferential {
 
     public isMatch (cd : ContentDifferential, allowPartial = false) {
         let check = this.getUnmatched(cd);
-        console.warn("Comparing", cd , "to ", check);
-        if ((allowPartial || check.unmatched.length == 0) && check.matching.length == 0) {
+        if ((allowPartial || (check.unmatched.length) <= 0) && check.matching.length == 0) {
             return true;
+        } else if ((allowPartial || (check.unmatched.length) <= 0) && check.matching.length > 0) {
+            for (let i = 0; i < check.matching.length; i++) {
+                if (!(check.matching[i] instanceof AdaptiveDifferential && (<AdaptiveDifferential> <unknown> check.matching[i]).countsAs == -1)) {
+                    return false;
+                }
+                return true;
+            }
         } else if (check.matching.length == 0) {
             for (let i = 0; i < check.unmatched.length; i++) {
                 if (!(check.unmatched[i] instanceof ContentMarker)) {
@@ -110,7 +116,10 @@ class ContentDifferential {
         if (a == undefined || a == null) {
             return true;
         }
-        if (typeof a == "function") {
+        if (a instanceof AdaptiveDifferential) {
+            //console.log(a, b, a.isMatch(b));
+            return a.isMatch(b);
+        } else if (typeof a == "function") {
             // b must inherit a or be a
             return b == a || b instanceof a || (typeof b == "function" && (<any>b).prototype instanceof a)
         } else if (a instanceof Thing) {

+ 15 - 0
app/World/Classes/ContentPicker/ContentGroup.ts

@@ -24,6 +24,13 @@ class ContentGroup {
         return this;
     }
 
+    public addDifferentials (...differentials : Array<any>) {
+        let unit = new ContentUnit();
+        unit.addCategory(...differentials);
+        this.addUnit(unit);
+        return this;
+    }
+
     public reset () {
         this.matching = this.units.slice();
     }
@@ -82,4 +89,12 @@ class ContentGroup {
         }
         return undefined;
     }
+
+    public getLength () {
+        return this.units.length;
+    }
+
+    public getUnit (n : number) {
+        return this.units[n];
+    }
 }

+ 0 - 3
app/World/Classes/Things/Humanoid/Humanoid.ts

@@ -670,9 +670,6 @@ class Humanoid extends Person {
                 penis.getSizeText(), (penis.isFlaccid() ? " flaccid " : " erect "),
                 Say.COCK, " between your legs"
             );
-            if (!penis.isBig() && penis.isGrower() && penis.isFlaccid()) {
-                say.add(", which is okay, since you're a grower, not a shower");
-            }
             if (penis.isUncovered()) {
                 let oneOf = new OneOf(OneOf.PURELY_AT_RANDOM, ...[
                     ", it is not covered by any clothing",

+ 1 - 1
app/World/TurnSequence.ts

@@ -99,7 +99,7 @@ module TurnSequence {
             await Elements.RememberedHandler.updateMap();
 
             let playerAction = <Action> rulebook.noun;
-            console.log(playerAction);
+
             if (playerAction) {
                 await Elements.HyperlinkHandler.hyperlinkObject(playerAction.getNoun(0));
             } else {

+ 80 - 2
content/main.ts

@@ -241,7 +241,7 @@ for (let i = 0; i < 0; i++) {
 }
 let randomOrc;
 let randomOrc2;
-for (let i = 0; i < 10; i++) {
+for (let i = 0; i < 2; i++) {
     let orc = new OrcDebugger();
     randomOrc = orc;
     if (randomOrc2 == undefined) {
@@ -301,4 +301,82 @@ spitroast.addUnit()
     .addUnit()
     .setFucker(OrcDebugger)
     .setHole(HumanoidHead)
-    .setStick(HumanoidPenis);
+    .setStick(HumanoidPenis);
+
+
+// (new CombatDescription("Poking 2")
+//     .setDescription("Oy cheeky kunt stahp that"))
+//     .addPokeUnit()
+//     .setTarget(Person)
+//     .addMarker(CombatPokeResult.ANNOYED);
+//
+// (new CombatDescription("Poking 1")
+//     .setDescription("Heh whatever"))
+//     .addPokeUnit()
+//     .setTarget(Person)
+//     .addMarker(CombatPokeResult.NOHEAT);
+//
+// (new CombatDescription("Poking 3")
+//     .setDescription("A'IGHT YOU GET FUCKED NOW MATE SWAER ON ME MUM"))
+//     .addPokeUnit()
+//     .setTarget(Person)
+//     .addMarker(CombatPokeResult.AGGROED);
+
+(new CombatPokeDescription("Hitting Orc"))
+    .setDescriptionFunction((target, markers) => {
+        let say = new Say(new SayBold(target), ": ");
+
+        if (markers.includes(CombatPokeResult.NOHEAT)) {
+            say.add(
+                new OneOf(OneOf.PURELY_AT_RANDOM,
+                    "Heh, ain't that cute?",
+                    "Pathetic."
+                )
+            );
+        } else if (markers.includes(CombatPokeResult.ANNOYED)) {
+            say.add(
+                new OneOf(OneOf.PURELY_AT_RANDOM,
+                    "Oy, stahp that.",
+                    "Ya' betta' stahp that before I getting mad."
+                )
+            );
+        } else if (markers.includes(CombatPokeResult.AGGROED)) {
+            say.add(
+                new OneOf(OneOf.PURELY_AT_RANDOM,
+                    "Aight. The axe it is."
+                )
+            );
+        }
+        return say;
+    })
+    .addUnit()
+    .setTarget(OrcDebugger)
+    .addMarker(AdaptiveDifferential.FULLYADAPTIVE(CombatPokeResult.AGGROED, CombatPokeResult.NOHEAT, CombatPokeResult.ANNOYED));
+
+
+(new CombatDescription("Allranging Fists"))
+    .setDescriptionFunction((actor, target, weapons, markers) => {
+        let say = new Say("You attack ", new SayThe(), target, " with your fists");
+        if (markers.indexOf(CombatHit.MISS) != -1) {
+            say.add(", but you miss");
+        } else if (markers.indexOf(CombatHit.CRITICAL) != -1) {
+            say.add(", it is a strong hit");
+        }
+
+        if (markers.indexOf(CombatResult.KNOCKED) != -1) {
+            say.add(", the strength of your attack knocks ", new SayHimHerIt(target), " on the floor.");
+        } else if (markers.indexOf(CombatResult.KNOCKED_OFF) != -1) {
+            say.add(", the strength of your attack knocks ", new SayHimHerIt(target), " unconscious.");
+        } else if (markers.indexOf(CombatResult.KILLED) != -1) {
+            say.add(", ", new SayHeSheIt(target), " dies.");
+        } else {
+            say.add(".");
+        }
+
+        return say;
+    })
+    .addUnit()
+    .setActor(WorldState.player)
+    .setTarget(Person)
+    .addMarker(AdaptiveDifferential.FULLYADAPTIVE(CombatHit.HIT, CombatHit.CRITICAL, CombatHit.MISS))
+    .addMarker(AdaptiveDifferential.FULLYADAPTIVE(CombatResult.KILLED, CombatResult.KNOCKED, CombatResult.KNOCKED_OFF));