Skip to content

Npc optimization - #2

Open
BXn4 wants to merge 43 commits into
mainfrom
npc-optimization
Open

Npc optimization#2
BXn4 wants to merge 43 commits into
mainfrom
npc-optimization

Conversation

@BXn4

@BXn4 BXn4 commented Sep 19, 2024

Copy link
Copy Markdown
Member

The timing is calculated based on the nearest position, not the object's actual position.

In the game, NPCs always choose the shortest path. Therefore, we need to determine the closest position to the counter and identify which side the waiter is positioned on.

Waiters more faster then the player, or the customers, so they arrive faster.

The new time values is:

  • Customers: distance / 1.85 (previously 1.95)
  • Waiters: distance / 2.30 (previously 1.95)

Waiters now have counter_side pos, and its used to calculate the time.
The simple pos is used to get the counter.

Waiters need the priority to send to the client.

[-] Removed getting random avatars in the npcs class.
[+] Added random avatars in the Avatar class.
[+] The customer cycle is now binded to the Café instead of the Player.
[+] Waiter have a priority value between 0 and 100.
- 0 = Clean only
- 50 = Booth
- 100 = Serve only

Customers spawn fixed random time.

  • Need to get the rating + luxury

Actions

  • Not saved in the DB.
  • Need to add/remove rating (ratings shouldn't fall below 1.0 (10) or go higher than 100.0 (1000)).
  • Waiters always move to another counter if it's empty.
  • If no counters have food, customers will wait until food is served to the counter or their waiting time runs out.

For the jobs, and spawning back the customers, we need to modify the code, but now its works wheel.
Vending machine interaction is not yet added

@SulivanM

Copy link
Copy Markdown

Nice, the code is better and optimised, its works in locally for my part.

@BXn4

BXn4 commented Sep 19, 2024

Copy link
Copy Markdown
Member Author

Could you test it with a maze like Café?

Need to do:
Place a chair and a table in near the door.
Place a chair and a table in the longest path.
And place some chairs randomly to tables.

If the customer waits longer before sit down in the longest path, something is still wrong.
And if the waiter too waits longer than usual.
They should sit down at the same time after arriving.

https://www.mazegenerator.net/

@BXn4
BXn4 requested a review from keremgokcek September 20, 2024 13:50
@BXn4 BXn4 added the enhancement New feature or request label Sep 24, 2024
Issue 1:
Waiter teleport issue (fixed)
Caused: Customer time_to_wait sleep for waiting to the waiter, its uses the old waiter.counter_pos, and uses the customers get_time, and the customers are slower. Fixed with: awaiting the serving task for the waiter.

Issue 2:
If the player clears the counter wheres the waiter is going (after the waiter wants to go to a new counter, because the current counter is empty) they starts serving an empty dish, because no logic implemented to prevent this. This logic was added, and if the serve_food returns true, its means the new counter have food, so they will serve it. If its false, then the customer leaves, because the player clean that counter. We can fix it, but we need to change the logic for the customer, to don't all tasks in one function. Like in the waiters.
@BXn4

BXn4 commented Sep 24, 2024

Copy link
Copy Markdown
Member Author

What was fixed?

Issue 1:
Waiter teleport issue (fixed)
Caused: Customer time_to_wait sleep for waiting to the waiter, its uses the old waiter.counter_pos, and uses the customers get_time, and the customers are slower. Fixed with: awaiting the serving task for the waiter.

Issue 2:
If the player clears the counter wheres the waiter is going (after the waiter wants to go to a new counter, because the current counter is empty) they starts serving an empty dish, because no logic implemented to prevent this. This logic was added, and if the serve_food returns true, its means the new counter have food, so they will serve it. If its false, then the customer leaves, because the player clean that counter. We can fix it, but we need to change the logic for the customer, to don't all tasks in one function. Like in the waiters. (fixed).

after.mp4
before.mp4

@BXn4 BXn4 assigned BXn4 and keremgokcek and unassigned BXn4 and keremgokcek Sep 24, 2024
@BXn4

BXn4 commented Sep 24, 2024

Copy link
Copy Markdown
Member Author

Here's how the game update the rating with the luxury value:
https://github.com/GGR-Devs/Cafe-Main/blob/2911a43b4d0972d2f1386edd782d3382f031f36d/com/goodgamestudios/cafe/model/components/CafeLevelData.as#L195

We need to add it too, to get correct values.

@BXn4

BXn4 commented Sep 29, 2024

Copy link
Copy Markdown
Member Author

What was fixed in the latest NPC bug fixes?

  • Waiters no longer freeze when they going to another customer on serve task.

      • Added a task to the waiters on serve.
      • Instead of await the customer eat function, now using create_task()
  • Improved the serve task.

  • Customers got a task when they waiting for waiter...

Now all NPCs should work.

Need more testings:

Deliver a food, then wait for the waiter to almost arrive, then clean the counter.
Repeat it some times. Remove the comment from the waiter serve task, to debug it.

Sometimes the waiters instantly deliver the food. Something cause that. If its happens to a lot of players need to look up what causes it. But for now, its okay, until there's no teleport issues.

@BXn4

BXn4 commented Oct 2, 2024

Copy link
Copy Markdown
Member Author

When the player clicks on a thirsty customer, their money, xp, rating updates instanly in the server side, and removes -1 drink from the machine.

The drink id is set to none (-1) in the customer cycle on customer action.fast_food, or when the player enters in the editor mode.

When the player enters, it will send the _use_vending_machine function to the player, which visually updates the vending machine amount. After its sending the ASY command to sync the money.

We can do it with temp amounts for the vending machine, but these cause sync errors. This is the best solution do it it.

Sadly, the xp is not updating. We can add it in the game ASY command to update it too.

@BXn4

BXn4 commented Oct 7, 2024

Copy link
Copy Markdown
Member Author

Added a new column in the db called daily_login

@BXn4

BXn4 commented Oct 7, 2024

Copy link
Copy Markdown
Member Author

Found some issues in the LBU and the waiter get_shortest_pos.

LBU issue:
Need to send the daily bonus when the player daily login past 24h.
Its sending, but its in a if function, what is checking the minutes past from the last login, and checks all counters.
If no counter found, or the player was not offline for 1 mins, the login bonus not called.
Need to move out.

The waiter issue:
If the waiter.pos is same as the counter.pos (like the chair is next to the counter) there's no objects between the counter and the waiter, so its throwing an error.
while loc1.parent and loc1.parent.position != self.start_node.position:

BXn4 added 3 commits October 10, 2024 09:17
The waiters pos not set from the objects actual position. It's set by the reachable closest object side.
To get the counter obj, just get the waiter.counter, instead of getting the object by the waiter pos
@BXn4

BXn4 commented Oct 11, 2024

Copy link
Copy Markdown
Member Author

Here's a small before / after comparison.

  • Getting a random avatar from the avatar class.
  • Customer cycle binded to the player.
  • Customers time: distance / 1.85.
  • Waiters time: distance / 2.30.
  • Waiters have priority between 0 and 100.
  • Getting the shortest position of the object (facing pos), and its used in the time calculation.
  • Rating update to dont go under 1.0 and 100.0.
  • Using the luxury value in the rating, if the rating is lower than the rating with luxury value.
  • Waiters always move to another counter if it's empty.
  • Customer tasks update (all tasks can be callable).
  • Added vending machine.
  • Added ASY on Café join.
  • Better spawn cycle.
  • Spawning back customers to visitor (client).
  • Customers giving rating + cash.
  • Counter food update on waiter deliver.
  • Getting the luxury value from the database before the rating.
  • Added NPC customize.
  • Added offline selling.
  • Added daily login bonus with random fancy reward.
  • Added a daily_login, and last_login column in the db.

New issue:
When the player disconnects, the customers not render, but when joining to the marketplace and back, the customers spawn back.

before.mp4
after.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants