Skip to content

Commit

Permalink
allow matt and mary can use specify skill
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Jan 26, 2025
1 parent e97c539 commit 959a3bc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/agent/NpcMary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
canChangeFavorability,
canGetFavorability,
} from "./tools/Favorability";
import { canCallPeople } from "./tools/Skill";

@injectable()
export class NpcMary {
Expand Down Expand Up @@ -42,6 +43,7 @@ export class NpcMary {
tools: {
getFavorability: canGetFavorability(this.name, city),
changeFavorability: canChangeFavorability(this.name, city),
callPeople: canCallPeople(city),
},
});

Expand Down
2 changes: 2 additions & 0 deletions src/agent/NpcMatt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
canChangeFavorability,
canGetFavorability,
} from "./tools/Favorability";
import { canEnableProtectMachine } from "./tools/Skill";

@injectable()
export class NpcMatt {
Expand Down Expand Up @@ -40,6 +41,7 @@ export class NpcMatt {
tools: {
getFavorability: canGetFavorability(this.name, city),
changeFavorability: canChangeFavorability(this.name, city),
enableProtectMachine: canEnableProtectMachine(city),
},
});

Expand Down
30 changes: 30 additions & 0 deletions src/agent/tools/Skill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { z } from "zod";
import { tool } from "ai";

import { City } from "@entity/City";

export function canEnableProtectMachine(city: City) {
return tool({
description:
"Can enable the protect machine to reduce damage rate, if the machine is already enabled it will return false",
parameters: z.object({}),
execute: async () => {
const success = city.enableProtectedMachine();

return { success };
},
});
}

export function canCallPeople(city: City) {
return tool({
description:
"Can call people to reduce damage rate, if the people is already called it will return false",
parameters: z.object({}),
execute: async () => {
const success = city.callPeople();

return { success };
},
});
}
3 changes: 3 additions & 0 deletions src/entity/City.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class City {
static readonly MAX_DAMAGE = 100;
static readonly MIN_DAMAGE = 0;
static readonly TARGET_DAMAGE_RATE = 0;
static readonly DAMAGE_RATE_DECREASE_RATIO = 0.25;
static readonly REQUIRED_MAX_FAVORABILITY_NPC = 3;
static readonly REQUIRED_MIN_FAVORABILITY = 80;

Expand Down Expand Up @@ -178,10 +179,12 @@ export class City {
public onEnableProtectedMachineEvent(
event: EnableProtectedMachineEvent,
): void {
this._damageRate = this._damageRate * City.DAMAGE_RATE_DECREASE_RATIO;
this._protecteMachineEnabled = true;
}

public onCallPeopleEvent(event: CallPeopleEvent): void {
this._damageRate = this._damageRate * City.DAMAGE_RATE_DECREASE_RATIO;
this._peopleIsCalled = true;
}
}

0 comments on commit 959a3bc

Please sign in to comment.