Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #81 from Pluviolithic/refactor/issue-64/improve-co…
Browse files Browse the repository at this point in the history
…mbat

Closes #64
  • Loading branch information
Pluviolithic authored Nov 16, 2023
2 parents aeffa77 + c83f588 commit 5249355
Show file tree
Hide file tree
Showing 14 changed files with 576 additions and 470 deletions.
38 changes: 38 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Contributing to Horror Simulator
Thanks for contributing to Horror Simulator! This guide has a few tips and guidelines to make contributing to the project as easy as possible.

## Bug Reports
Any bugs (or things that look like bugs) can be reported on the [GitHub issue tracker](https://github.com/pluviolithic/horror-simulator/issues)

Make sure you check to see if someone has already reported your bug first!

## Working on Horror Simulator
To get started working on Horror Simulator, you'll need:
* Git
* [Wally](https://github.com/UpliftGames/wally)
* [StyLua](https://github.com/JohnnyMorganz/StyLua)
* [Selene](https://github.com/Kampfkarren/selene)

The `setup` make target will automatically install and configure all of them via aftman.
```sh
git clone https://github.com/pluviolithic/horror-simulator/
cd horror-simulator
make setup
```

### Pull Requests
Before starting a pull request, open an issue about the feature or bug. This helps us prevent duplicated and wasted effort. These issues are a great place to ask for help if you run into problems!

Before you submit a new pull request, check:
* Code Quality: Run [Selene](https://github.com/Kampfkarren/selene) on your code, no warnings allowed!
* Code Style: Run [StyLua](https://github.com/JohnnyMorganz/StyLua) on your code so it's formatted to follow the Roblox Lua Style Guide

### Code Style
Try to match the existing code style! In short:

* Tabs for indentation
* Double quotes
* One statement per line

Use StyLua to automatically format your code to comply with the Roblox Lua Style Guide.
You can run this tool manually from the commandline (`stylua -c src/`), or use one of StyLua's editor integrations.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
setup:
curl https://sh.rustup.rs -sSf | sh -s -- -y
cargo install aftman
aftman self-install
aftman install --no-trust-check
wally install
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
# horror-simulator
# horror-simulator
Generated by [Rojo](https://github.com/rojo-rbx/rojo) 7.3.0.

## Getting Started
To install the necessary tooling, use:
```sh
make setup
```

To build the place from scratch, use:

```sh
rojo build -o "horror-simulator.rbxlx"
```

Next, open `horror-simulator.rbxlx` in Roblox Studio and start the Rojo server:

```sh
rojo serve
```

For more help, check out [the Rojo documentation](https://rojo.space/docs).

## Contributing

See [the contribution guide](CONTRIBUTING.md) before contributing!
54 changes: 27 additions & 27 deletions default.project.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"name": "horror-simulator",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"Common": {
"$path": "src/shared",
"lib": {
"$className": "Folder",
"$path": "./Packages"
}
}
},
"ServerScriptService": {
"Server": {
"$path": "src/server",
"lib": {
"$className": "Folder",
"$path": "./ServerPackages"
}
}
},
"StarterPlayer": {
"StarterPlayerScripts": {
"Client": {
"$path": "src/client"
}
}
"name": "horror-simulator",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"Common": {
"$path": "src/shared",
"lib": {
"$className": "Folder",
"$path": "./Packages"
}
}
},
"ServerScriptService": {
"Server": {
"$path": "src/server",
"lib": {
"$className": "Folder",
"$path": "./ServerPackages"
}
}
},
"StarterPlayer": {
"StarterPlayerScripts": {
"Client": {
"$path": "src/client"
}
}
}
}
}
10 changes: 7 additions & 3 deletions src/client/GameAtmosphere/Soundscape/PrimaryRegionSelector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ store.changed:connect(function(newState, oldState)

-- verify whether this actually does anything
if
Sift.Array.equals(
Sift.Dictionary.keys(oldSoundRegions.OccupiedSoundRegions),
Sift.Dictionary.keys(newSoundRegions.OccupiedSoundRegions)
not newSoundRegions
or (
oldSoundRegions
and Sift.Array.equals(
Sift.Dictionary.keys(oldSoundRegions.OccupiedSoundRegions),
Sift.Dictionary.keys(newSoundRegions.OccupiedSoundRegions)
)
)
then
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ for _, playlistFolder in playlists:GetChildren() do
volumeKnobs.on[playlistFolder.Name] = createKnob(nextAudioInstance, true)
volumeKnobs.off[playlistFolder.Name] = createKnob(nextAudioInstance, false)

if selectors.getAudioData(store:getState(), player.Name).PrimarySoundRegion ~= playlistFolder.Name then
if
not selectors.isPlayerLoaded(store:getState(), player.Name)
or selectors.getAudioData(store:getState(), player.Name).PrimarySoundRegion
~= playlistFolder.Name
then
nextAudioInstance.Volume = 0
end

Expand Down
49 changes: 49 additions & 0 deletions src/server/Combat/Enemies/ApplyDamageToEnemy.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
local ReplicatedStorage = game:GetService "ReplicatedStorage"
local ServerScriptService = game:GetService "ServerScriptService"

local store = require(ServerScriptService.Server.State.Store)
local actions = require(ServerScriptService.Server.State.Actions)
local selectors = require(ReplicatedStorage.Common.State.selectors)
local animationUtilities = require(ReplicatedStorage.Common.Utils.AnimationUtils)

local weapons = ReplicatedStorage.Weapons

local function canAttack(player, enemy, info)
if not enemy:IsDescendantOf(game) then
return false
end

local rootPart = if enemy.Humanoid.RootPart then enemy.Humanoid.RootPart else enemy:FindFirstChild "RootPart"
local fightRange = enemy.Configuration.FightRange.Value

return info.HealthValue.Value > 0
and selectors.isPlayerLoaded(store:getState(), player.Name)
and selectors.getCurrentTarget(store:getState(), player.Name) == enemy
and player:DistanceFromCharacter(rootPart.Position) <= fightRange + 10
end

return function(player, enemy, info, janitor)
local weaponName = selectors.getEquippedWeapon(store:getState(), player.Name)
local damageMultiplier = if weaponName == "Fists" then 1 else weapons[weaponName].Damage.Value

store:dispatch(actions.combatBegan(player.Name))

if weaponName ~= "Fists" then
local weaponAccessory = weapons[weaponName]:Clone()
player.Character.Humanoid:AddAccessory(weaponAccessory)
janitor:Add(weaponAccessory)
end

task.spawn(function()
while canAttack(player, enemy, info) do
local damageToDeal = math.clamp(
selectors.getStat(store:getState(), player.Name, "Strength") * damageMultiplier,
0,
info.HealthValue.Value
)
info.DamageDealtByPlayer[player] = (info.DamageDealtByPlayer[player] or 0) + damageToDeal
info.HealthValue.Value -= damageToDeal
task.wait(animationUtilities.getPlayerAttackSpeed(player))
end
end)
end
44 changes: 44 additions & 0 deletions src/server/Combat/Enemies/ApplyDamageToPlayers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
local ReplicatedStorage = game:GetService "ReplicatedStorage"
local CollectionService = game:GetService "CollectionService"
local ServerScriptService = game:GetService "ServerScriptService"

local bossAttackSpeed = ReplicatedStorage.Config.Combat.BossAttackSpeed.Value
local enemyAttackSpeed = ReplicatedStorage.Config.Combat.EnemyAttackSpeed.Value

local store = require(ServerScriptService.Server.State.Store)
local actions = require(ServerScriptService.Server.State.Actions)
local selectors = require(ReplicatedStorage.Common.State.selectors)

return function(enemy, info, janitor)
if info.DamageActive then
return
end
info.DamageActive = true

local attackDelay = if CollectionService:HasTag(enemy, "Boss") then bossAttackSpeed else enemyAttackSpeed
local damagePlayers = true

task.spawn(function()
while damagePlayers do
for _, player in info.EngagedPlayers do
local fearMeterGoal = math.min(
selectors.getStat(store:getState(), player.Name, "CurrentFearMeter")
+ enemy.Configuration.Damage.Value,
selectors.getStat(store:getState(), player.Name, "MaxFearMeter")
)
local fearMeterAddendum = fearMeterGoal
- selectors.getStat(store:getState(), player.Name, "CurrentFearMeter")

if fearMeterAddendum ~= 0 then
store:dispatch(actions.incrementPlayerStat(player.Name, "CurrentFearMeter", fearMeterAddendum))
end
end
task.wait(attackDelay)
end
end)

janitor:Add(function()
info.DamageActive = nil
damagePlayers = false
end, true)
end
42 changes: 42 additions & 0 deletions src/server/Combat/Enemies/ApplyEnemyAnimations.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local ReplicatedStorage = game:GetService "ReplicatedStorage"
local CollectionService = game:GetService "CollectionService"

local bossAttackSpeed = ReplicatedStorage.Config.Combat.BossAttackSpeed.Value
local enemyAttackSpeed = ReplicatedStorage.Config.Combat.EnemyAttackSpeed.Value

local animationUtilities = require(ReplicatedStorage.Common.Utils.AnimationUtils)

return function(enemy, info, janitor)
if info.AnimationsActive then
return
end
info.AnimationsActive = true

local attackDelay = if CollectionService:HasTag(enemy, "Boss") then bossAttackSpeed else enemyAttackSpeed
local runAnimations = true

local animationInstances =
animationUtilities.filterAndSortAnimationInstances(enemy.Configuration.AttackAnims:GetChildren())
local currentIndex, animationTrack, animation = 0, nil, nil

task.spawn(function()
while runAnimations do
currentIndex, animation = animationUtilities.getNextIndexAndAnimationTrack(animationInstances, currentIndex)
animationTrack = enemy.Humanoid:LoadAnimation(animation)
animationTrack.Priority = Enum.AnimationPriority.Action

animationTrack:Play()
animationTrack.Stopped:Wait()
animationTrack:Destroy()
task.wait(attackDelay)
end
end)

janitor:Add(function()
runAnimations = false
info.AnimationsActive = nil
if animationTrack.IsPlaying then
animationTrack:Stop()
end
end, true)
end
37 changes: 37 additions & 0 deletions src/server/Combat/Enemies/ApplyPlayerAnimations.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local ReplicatedStorage = game:GetService "ReplicatedStorage"
local ServerScriptService = game:GetService "ServerScriptService"

local combatAnimations = ReplicatedStorage.CombatAnimations

local store = require(ServerScriptService.Server.State.Store)
local selectors = require(ReplicatedStorage.Common.State.selectors)
local animationUtilities = require(ReplicatedStorage.Common.Utils.AnimationUtils)

return function(player, janitor)
local runAnimations = true

local currentIndex, animationTrack, animation = 0, nil, nil
local animationInstances = animationUtilities.filterAndSortAnimationInstances(
combatAnimations[selectors.getEquippedWeapon(store:getState(), player.Name)]:GetChildren()
)

task.spawn(function()
while runAnimations do
currentIndex, animation = animationUtilities.getNextIndexAndAnimationTrack(animationInstances, currentIndex)
animationTrack = player.Character.Humanoid:LoadAnimation(animation)
animationTrack.Priority = Enum.AnimationPriority.Action

animationTrack:Play()
animationTrack.Stopped:Wait()
animationTrack:Destroy()
task.wait(animationUtilities.getPlayerAttackSpeed(player))
end
end)

janitor:Add(function()
runAnimations = false
if animationTrack.IsPlaying then
animationTrack:Stop()
end
end, true)
end
Loading

0 comments on commit 5249355

Please sign in to comment.