Merge pull request #1781 from danielyxie/dev

gang with 0 territory cannot fight
This commit is contained in:
hydroflame 2021-11-24 17:58:37 -05:00 committed by GitHub
commit c2b58ffcce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 61 deletions

24
dist/vendor.bundle.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -190,56 +190,62 @@ export class Gang {
} }
// Then process territory // Then process territory
for (let i = 0; i < GangConstants.Names.length; ++i) { const gangs = GangConstants.Names.filter((g) => AllGangs[g].territory > 0);
const others = GangConstants.Names.filter((e) => { if (gangs.length > 1) {
return e !== GangConstants.Names[i]; for (let i = 0; i < gangs.length; ++i) {
}); const others = gangs.filter((e) => {
const other = getRandomInt(0, others.length - 1); return e !== gangs[i];
});
const other = getRandomInt(0, others.length - 1);
const thisGang = GangConstants.Names[i]; const thisGang = gangs[i];
const otherGang = others[other]; const otherGang = others[other];
// If either of the gangs involved in this clash is the player, determine // If either of the gangs involved in this clash is the player, determine
// whether to skip or process it using the clash chance // whether to skip or process it using the clash chance
if (thisGang === gangName || otherGang === gangName) { if (thisGang === gangName || otherGang === gangName) {
if (!(Math.random() < this.territoryClashChance)) continue; if (!(Math.random() < this.territoryClashChance)) continue;
}
const thisPwr = AllGangs[thisGang].power;
const otherPwr = AllGangs[otherGang].power;
const thisChance = thisPwr / (thisPwr + otherPwr);
function calculateTerritoryGain(winGang: string, loseGang: string): number {
const powerBonus = Math.max(1, 1 + Math.log(AllGangs[winGang].power / AllGangs[loseGang].power) / Math.log(50));
const gains = Math.min(AllGangs[loseGang].territory, powerBonus * 0.0001 * (Math.random() + 0.5));
return gains;
}
if (Math.random() < thisChance) {
if (AllGangs[otherGang].territory <= 0) return;
const territoryGain = calculateTerritoryGain(thisGang, otherGang);
AllGangs[thisGang].territory += territoryGain;
AllGangs[otherGang].territory -= territoryGain;
if (thisGang === gangName) {
this.clash(true); // Player won
AllGangs[otherGang].power *= 1 / 1.01;
} else if (otherGang === gangName) {
this.clash(false); // Player lost
} else {
AllGangs[otherGang].power *= 1 / 1.01;
} }
} else {
if (AllGangs[thisGang].territory <= 0) return; const thisPwr = AllGangs[thisGang].power;
const territoryGain = calculateTerritoryGain(otherGang, thisGang); const otherPwr = AllGangs[otherGang].power;
AllGangs[thisGang].territory -= territoryGain; const thisChance = thisPwr / (thisPwr + otherPwr);
AllGangs[otherGang].territory += territoryGain;
if (thisGang === gangName) { function calculateTerritoryGain(winGang: string, loseGang: string): number {
this.clash(false); // Player lost const powerBonus = Math.max(
} else if (otherGang === gangName) { 1,
this.clash(true); // Player won 1 + Math.log(AllGangs[winGang].power / AllGangs[loseGang].power) / Math.log(50),
AllGangs[thisGang].power *= 1 / 1.01; );
const gains = Math.min(AllGangs[loseGang].territory, powerBonus * 0.0001 * (Math.random() + 0.5));
return gains;
}
if (Math.random() < thisChance) {
if (AllGangs[otherGang].territory <= 0) return;
const territoryGain = calculateTerritoryGain(thisGang, otherGang);
AllGangs[thisGang].territory += territoryGain;
AllGangs[otherGang].territory -= territoryGain;
if (thisGang === gangName) {
this.clash(true); // Player won
AllGangs[otherGang].power *= 1 / 1.01;
} else if (otherGang === gangName) {
this.clash(false); // Player lost
} else {
AllGangs[otherGang].power *= 1 / 1.01;
}
} else { } else {
AllGangs[thisGang].power *= 1 / 1.01; if (AllGangs[thisGang].territory <= 0) return;
const territoryGain = calculateTerritoryGain(otherGang, thisGang);
AllGangs[thisGang].territory -= territoryGain;
AllGangs[otherGang].territory += territoryGain;
if (thisGang === gangName) {
this.clash(false); // Player lost
} else if (otherGang === gangName) {
this.clash(true); // Player won
AllGangs[thisGang].power *= 1 / 1.01;
} else {
AllGangs[thisGang].power *= 1 / 1.01;
}
} }
} }
} }