瀏覽代碼

Moves can have weights now.

tags/v0.2.8
Fen Dweller 7 年之前
父節點
當前提交
7e622a9789
共有 3 個文件被更改,包括 55 次插入16 次删除
  1. +34
    -8
      combat.js
  2. +19
    -0
      feast.js
  3. +2
    -8
      vore.js

+ 34
- 8
combat.js 查看文件

@@ -14,6 +14,21 @@ function isGrappled(entity) {
return entity.grappled == true;
}

function doComp(attackStat, defendStat) {
return Math.random() * attackStat > Math.random() * defendStat;
}

function statCheck(attacker, defender, stat) {
return doComp(attacker[stat], defender[stat]);
}

function statHealthCheck(attacker, defender, stat) {
let attackerPercent = attacker.health / attacker.maxHealth;
let defenderPercent = defender.health / defender.maxHealth;

return doComp(attacker[stat] * attackerPercent, defender[stat] * defenderPercent);
}

function punchAttack(attacker) {
return {
name: "Punch",
@@ -51,7 +66,7 @@ function grapple(attacker) {
name: "Grapple",
desc: "Try to grab your opponent",
attack: function(defender) {
let success = Math.random() < 0.5;
let success = statHealthCheck(attacker, defender, "str");
if (success) {
defender.grappled = true;
return "You charge at the " + defender.description() + ", tackling them and knocking them to the ground.";
@@ -80,7 +95,7 @@ function grappleDevour(attacker) {
name: "Devour",
desc: "Try to consume your grappled opponent",
attack: function(defender) {
let success = Math.random() < 0.25 + (1 - defender.health / defender.maxHealth) * 0.75;
let success = statHealthCheck(attacker, defender, "str");
if (success) {
attacker.stomach.feed(defender);
defender.grappled = false;
@@ -91,7 +106,7 @@ function grappleDevour(attacker) {
}
},
attackPlayer: function(defender) {
let success = Math.random() < 0.5 + (1 - defender.health / defender.maxHealth)*0.5 && Math.random() < 0.5;
let success = statHealthCheck(attacker, defender, "str");
if(success) {
defender.grappled = false;
changeMode("eaten");
@@ -113,7 +128,7 @@ function grappleAnalVore(attacker) {
name: "Anal Vore",
desc: "Try to shove your opponent up your ass.",
attack: function(defender) {
let success = Math.random() < 0.25 + (1 - defender.health / defender.maxHealth) * 0.75;
let success = statHealthCheck(attacker, defender, "str");
if (success) {
attacker.butt.feed(defender);
defender.grappled = false;
@@ -150,7 +165,7 @@ function grappledStruggle(attacker) {
name: "Struggle",
desc: "Try to break your opponent's pin",
attack: function(defender) {
let success = Math.random() < 0.5 + (1 - defender.health / defender.maxHealth)*0.5;
let success = statHealthCheck(attacker, defender, "str");
if (success) {
attacker.grappled = false;
return "You struggle and shove the " + defender.description() + " off of you.";
@@ -159,7 +174,7 @@ function grappledStruggle(attacker) {
}
},
attackPlayer: function(defender) {
let success = Math.random() < 0.5 + (1 - defender.health / defender.maxHealth)*0.5 && Math.random() < 0.5;
let success = statHealthCheck(attacker, defender, "str");
if (success) {
attacker.grappled = false;
return "Your prey shoves you back, breaking your grapple!";
@@ -179,7 +194,7 @@ function grappledReverse(attacker) {
name: "Reversal",
desc: "Try to pin your grappler. Less likely to work than struggling.",
attack: function(defender) {
let success = Math.random() < 0.25 + (1 - defender.health / defender.maxHealth) * 0.5;
let success = statHealthCheck(attacker, defender, "str");
if (success) {
attacker.grappled = false;
defender.grappled = true;
@@ -189,7 +204,7 @@ function grappledReverse(attacker) {
}
},
attackPlayer: function(defender) {
let success = Math.random() < 0.5 + (1 - defender.health / defender.maxHealth)*0.5 && Math.random() < 0.5;
let success = statHealthCheck(attacker, defender, "str");
if (success) {
attacker.grappled = false;
defender.grappled = true;
@@ -272,3 +287,14 @@ function digestPlayerStomach(predator,damage=20) {
priority: 1,
};
}

function instakillPlayerStomach(pedator) {
return {
digest: function(player) {
player.health = -100;
return "The stomach walls churn, clench, and swiftly crush you into nothingnes.";
},
priority: 1,
weight: function(attacker, defender) { return 1/3 },
};
}

+ 19
- 0
feast.js 查看文件

@@ -21,6 +21,25 @@ let prefs = {
}
};

function pick(list) {
if (list.length == 0)
return null;
else {
let sum = list.reduce((sum, choice) => choice.weight == undefined ? 1 : choice.weight() + sum, 0);

let target = Math.random() * sum;

for (let i = 0; i < list.length; i++) {
sum -= list[i].weight == undefined ? 1 : list[i].weight();
if (sum <= target) {
return list[i];
}
}

return list[list.length-1];
}
}

function filterValid(options, attacker, defender) {
let filtered = options.filter(option => option.conditions == undefined || option.conditions.reduce((result, test) => result && test(prefs, attacker === player), true));
return filtered.filter(option => option.requirements == undefined || option.requirements.reduce((result, test) => result && test(attacker, defender), true));


+ 2
- 8
vore.js 查看文件

@@ -1,12 +1,5 @@
"use strict";

function pick(list) {
if (list.length == 0)
return null;
else
return list[Math.floor(Math.random()*list.length)];
}

function Creature(name = "Creature", str=10, dex=10, con=10) {
this.name = name;

@@ -99,7 +92,7 @@ function Anthro() {
}

function Fen() {
Anthro.call(this, name);
Anthro.call(this, name, 1000000, 1099900, 1000000);

this.build = "loomy";
this.species = "crux";
@@ -117,6 +110,7 @@ function Fen() {
this.digests = [];

this.digests.push(new digestPlayerStomach(this,50));
this.digests.push(new instakillPlayerStomach(this));

this.backupDigest = new digestPlayerStomach(this,50);
}


Loading…
取消
儲存