Remove item when npc gives it to player

main
Cameron Murphy Reikes 2 years ago
parent 530f929376
commit 7236b4e935

@ -741,9 +741,8 @@ void reset_level()
update_player_from_entities();
BUFF_APPEND(&player->held_items, ITEM_WhiteSquare);
for(int i = 0; i < 30; i++)
for(int i = 0; i < 20; i++)
BUFF_APPEND(&player->held_items, ITEM_Boots);
BUFF_APPEND(&player->held_items, ITEM_Tripod);
ENTITIES_ITER(gs.entities)
{
@ -829,10 +828,10 @@ void end_text_input(char *what_player_said)
}
if(talking->last_seen_holding_kind != player_holding)
{
process_perception(talking, (Perception){.type = PlayerHeldItemChanged, .holding = player_holding,});
process_perception(talking, (Perception){.type = PlayerHeldItemChanged, .holding = player_holding,}, player);
}
process_perception(talking, (Perception){.type = PlayerDialog, .player_dialog = what_player_said_sentence,});
process_perception(talking, (Perception){.type = PlayerDialog, .player_dialog = what_player_said_sentence,}, player);
}
}
/*
@ -1604,11 +1603,11 @@ void request_do_damage(Entity *to, Entity *from, float damage)
{
if(from->is_character)
{
process_perception(to, (Perception){.type = PlayerAction, .player_action_type = ACT_hits_npc, .damage_done = damage,});
process_perception(to, (Perception){.type = PlayerAction, .player_action_type = ACT_hits_npc, .damage_done = damage,}, player);
}
else
{
process_perception(to, (Perception){.type = EnemyAction, .enemy_action_type = ACT_hits_npc, .damage_done = damage,});
process_perception(to, (Perception){.type = EnemyAction, .enemy_action_type = ACT_hits_npc, .damage_done = damage,}, player);
}
}
to->vel = MulV2F(NormV2(SubV2(to->pos, from_point)), 15.0f);
@ -3215,7 +3214,7 @@ F cost: G + H
}
Perception p = {0};
assert(parse_chatgpt_response(it, mocked_ai_response.data, &p));
process_perception(it, p);
process_perception(it, p, player);
#undef SAY
#endif
it->perceptions_dirty = false;

@ -363,7 +363,7 @@ int action_to_index(Entity *it, Action a)
return index;
}
void process_perception(Entity *it, Perception p)
void process_perception(Entity *it, Perception p, Entity *player)
{
if(it->is_npc)
{
@ -401,6 +401,34 @@ void process_perception(Entity *it, Perception p)
{
it->standing = STANDING_JOINED;
}
else if(p.npc_action_type == ACT_give_item)
{
int item_to_remove = -1;
Entity *e = it;
BUFF_ITER_I(ItemKind, &e->held_items, i)
{
if(*it == p.given_item)
{
item_to_remove = i;
break;
}
}
if(item_to_remove < 0)
{
Log("Can't find item %s to give from NPC %s to the player\n", items[p.given_item].name, characters[it->npc_kind].name);
assert(false);
}
else
{
BUFF_REMOVE_AT_INDEX(&it->held_items, item_to_remove);
BUFF_APPEND(&player->held_items, p.given_item);
}
}
else
{
// actions that take an argument have to have some kind of side effect based on that argument...
assert(!actions[p.npc_action_type].takes_argument);
}
}
}
}

Loading…
Cancel
Save