effect_execution.clj

Branches > main > d1e5602 > files / src / net / bowmap / stormbow / effect_execution.clj

(ns net.bowmap.stormbow.effect-execution
  (:require
   [net.bowmap.protocol.packet :as pk]
   [net.bowmap.protocol.packet.clientbound :as clientbound]
   [net.bowmap.server.player :as player]
   [net.bowmap.server.server :as server]
   [net.bowmap.server.text :as text]
   [net.bowmap.stormbow.effect :as effect]
   [net.bowmap.transport.connection :as connection]))

(defmulti execute-effect!
  (fn [{:keys! [::effect/id]}]
    id))

(defn send-packet! [uuid packet]
  (let [{::connection/keys! [connection]} (@server/players uuid)
        {::connection/keys! [send-packet]} connection]
    (send-packet packet)))

(defmethod execute-effect! ::effect/send-chat-message [{::player/keys! [uuid] ::text/keys! [component]}]
  (send-packet! uuid {::pk/id ::clientbound/system-chat-message
                      ; TODO could rename this key
                      :message component}))

(defn execute-effects! [effects]
  (run! execute-effect! effects))